Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

multi line text box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kevin R - 17 Nov 2006 15:37 GMT
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.
Peter Jamieson - 17 Nov 2006 17:18 GMT
> 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

>I have a multi line text box on a userform as an address field.  The user
> would enter the address as:
[quoted text clipped - 9 lines]
>
> Why is it inserting a blank space in front of the second line??  Thanks.
Kevin R - 20 Nov 2006 20:32 GMT
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

> > Why is it inserting a blank space in front of the second line??  Thanks.
>
[quoted text clipped - 22 lines]
> >
> > Why is it inserting a blank space in front of the second line??  Thanks.
Peter Jamieson - 30 Nov 2006 09:19 GMT
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

> I've tried using vbCr, vbCrLf, chr(13), chr(10), nothing seems to work.
> Here's the code:
[quoted text clipped - 48 lines]
>> > Why is it inserting a blank space in front of the second line??
>> > Thanks.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.