Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

striping carraige return & Line feed from text box. 2

Status
Not open for further replies.

Waiman

Programmer
Sep 11, 2001
15
0
0
GB
I have a multi-line text box which is used in a form in Word, using VBA. The contents of the text box is put into a Docvaraible. The problem I have is that all carriage returns are not displaying properly, the square character is used. I can strip out the carraige return and line feed but I can't get the docvariable to force a 'hidden' carriage return and linefeed.

Any help appreciated.



 
Also consider knowing the Asc of each character.
See Character Sets.....
The Asc(yourvariable) for linefield is 10
The Asc(yourvariable) for carriage return is 13
This routinne ensures at least 1 character is entered
and that something is entered and the checks for linefeeds
or carriage returns which as is quite useless....needs expansion via character set ranges.

'--------------------------
ordernumberraw = TextBox2.Value
ordernumber = Trim(ordernumberraw)
lengthordernumber = Len(ordernumber)

If lengthordernumber < 1 Then
MsgBox &quot;Please enter a valid Order #&quot;, vbOKOnly, &quot;Incorrect input&quot;
TextBox2.Value = Empty
GoTo endsubmit
End If

For x = 1 To lengthordernumber
d = Mid(ordernumber, x, 1)
b = Asc(d)

If b = 10 Or b = 13 Then
MsgBox &quot;Please enter a valid Order #&quot;, vbOKOnly, &quot;Incorrect input&quot;
TextBox2.Value = Empty
TextBox2.SetFocus
GoTo endsubmit
End If
Next x
 
He WANTS to be able to enter multiple lines in the text box. The problem comes about when the contents of the textbox are assigned to a Wird DocVariable and eventually printed by Word. Word does not &quot;like&quot; vbCrLf in a field but behaves nicely when fed a line feed. Thus the Replace(strText,vbCrLf,vbLF)
 
Thanks guys. I've tried JohnYingLing's suggestion, but it still shows the Square character.

Tried replacing chr(10), chr(13), vbCRLF, vbLF - no avail.

Would the font be an issue? I'm using verdana.

 
Thanks JohnYingLing, You were right, kind of.

I had to replace the vbLF NOT the vbCR, as you had stated, but I'm sure you just got them mixed up. :)

For others it should be,

Replace(strText,vbCrLf,vbCr)

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top