Adding a "Linefeed" in a Label/Text Box

G

Guest

Hi, from my VBA code I am creating a dynamic control Label and Text Box. I
need to force a "line feed" or "carriage return" in in the middle of the
text. I tried adding a Chr(10) and Chr(13) value to the string but this did
not work. For example,

Dim foo As String
foo = " some text "
foo = foo + Chr (13) ' ASCII Carriage Return Char
foo = foo + " some text"
Me.TextBox.TEXT = foo

This code does not work. Can someone provide a solution to this problem,

Thanks,
 
J

Jacco

Eddie's Bakery and Cafe' said:
Hi, from my VBA code I am creating a dynamic control Label and Text Box.
I
need to force a "line feed" or "carriage return" in in the middle of the
text. I tried adding a Chr(10) and Chr(13) value to the string but this
did
not work. For example,

Dim foo As String
foo = " some text "
foo = foo + Chr (13) ' ASCII Carriage Return Char
foo = foo + " some text"
Me.TextBox.TEXT = foo

This code does not work. Can someone provide a solution to this problem,

Thanks,

Try this:

foo = foo & Chr (13) ' ASCII Carriage Return Char
 
G

Guest

Hi Jacco, I tried using the "&" but this did not work. Do you have another
suggestion?

Thanks for your help
 
M

Mark

Try:
foo=foo & vbCrLf

Eddie's Bakery and Cafe' said:
Hi Jacco, I tried using the "&" but this did not work. Do you have
another
suggestion?

Thanks for your help
 
F

fredg

Hi, from my VBA code I am creating a dynamic control Label and Text Box. I
need to force a "line feed" or "carriage return" in in the middle of the
text. I tried adding a Chr(10) and Chr(13) value to the string but this did
not work. For example,

Dim foo As String
foo = " some text "
foo = foo + Chr (13) ' ASCII Carriage Return Char
foo = foo + " some text"
Me.TextBox.TEXT = foo

This code does not work. Can someone provide a solution to this problem,

Thanks,

In Access you must use the chr(13) & chr(10) combination
IN THAT ORDER.

= "Line 1." & chr(13) & chr(10) & "Line 2."

In VBA you can also use vbCrLf or vbNewLine.

[SomeControl] = "Line 1." & vbCrLf & "Line 2."
 
T

Tim Ferguson

Me.TextBox.TEXT = foo

You cannot access the Text property of a control (unless it has the focus).
Try

Me!textbox.Value = "foo" & vbCrLf & "foo again"


HTH


Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top