multi line text box

K

Kevin R

I have a multi line text box on a userform as an address field. The user
would enter the address as:

301 1st Street
Mytown, DC 12345

BUT, when the document is generated the address is carried over (as a
DOCVARIABLE) and shown as:

301 1st Street
Mytown, DC 12345

Why is it inserting a blank space in front of the second line?? Thanks.
 
P

Peter Jamieson

Why is it inserting a blank space in front of the second line?? Thanks.

Because a multiline string in a text box has a different representation from
the "same" string in a Word document. The line break in the text box is
represented by character 13 followed by character 10. To get a new paragraph
mark in Word, you only need to insert a 13. The 10 results in something that
looks like a space.

I expect others here have more practical experience of this than I do, but
that's roughly what is going on anyway.

Peter Jamieson
 
K

Kevin R

I've tried using vbCr, vbCrLf, chr(13), chr(10), nothing seems to work.
Here's the code:

With cboHOName
If cboHOName.Value = "Baltimore" Then
txtAddress.Text = "1000 Park Avenue, Suite 500" & vbCrLf &
"Baltimore, MD 21201"
ElseIf cboHOName.Value = "Charleston" Then
txtAddress.Text = "1000 Quarrier Street, Suite 500" & vbCr &
"Charleston, WV 25301"
End If
End With

No matter what I use, I still end up with something the blank space in the
document in front of the 2nd line of the address.

1000 Quarrier Street, Suite 500
Charleston, WV 25301
 
P

Peter Jamieson

Sorry, I've been away.

<aybe you found the answer elsewhere. If not,
a. when I use your code to /populate/ my text box, there is no extra space
at the beginning of the line (e.g. when using vbCrLf.
b. it's when you get that text back and put it into a document variable
that the problem starts (or indeed, you would have the same problem if you
set your document variable text to the string with vbCrLf in it). In other
words, the text box is always giving you a vbCrLf back regardless of what
line end characters you use
c. so you need to process the string you get back from the text box before
you assign it to the document variable, e.g. use something like

ActiveDocument.Variables.Add Name:="myvariable",
Value:=Replace(TextBox1.Text, vbCrLf, vbCr)

Peter Jamieson
 

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