Find and Replace

R

Rick English

I have written a macro to replace specific text with the contents of a
textbox on a form. If the textbox contains multiple lines then the resulting
replacement does not have multiple lines. I searched the textbox contents
and the ascii characters 13 and 10 are at the end of each line (as they
should be). The replacement shows two null characters

How can I get multiple lines instead?

I should also mention that the replacements are, for the most part, taking
place in table cells


Rick English English Pool Consulting 1445 Twenty Eighth Street
(e-mail address removed) tel: fax: mobile: 619-338-9197 619-338-9167 619-818-3052
Add me to your address book... Want a signature like this?
 
R

Rick English

Since I got no answer I can only assume that my problem is trivial,
unanswerable or, most likely, that I did not give enough information. I'll
operate on the assumption

here is a typical call"

Call find_replace_text("&buyers_name", frmInitialdata.txtbuyersname.Text)

Here is the code


Sub find_replace_text(oldtext As String, newtext As String)
'
' find_replace Macro
Set myrange = ActiveDocument.Content
Call Check_Text(newtext)
With myrange.Find
.ClearFormatting
.Text = oldtext
With .Replacement
.Text = newtext
End With
.Execute Replace:=wdReplaceAll, Format:=True
End With
End Sub

' I wrote this sub to check to see if the correct ASCII characters were
being sent. Newstring should have CHR$(13) and CHR$(10) at the end of each
line.
' By stepping through the routine below, I confirmed that both those
characters were present. So this routine is going to be deleted
' So I know that the newtext string has the right content.
'

Sub Check_Text(newtext As String)
Dim text0 As String
Dim text1 As String
Dim index As Integer
text0 = ""
For index = 1 To Len(newtext)
text1 = Mid$(newtext, index, 1)
Select Case Asc(text1)
Case Is = 13
text0 = text0 & Chr(13)
Case 32 To 127
text0 = text0 & text1
Case Else
text1 = text1
End Select
Next index
newtext = text0
End Sub
 
J

Jay Freedman

Hi, Rick,

The problem is that the textbox and the document don't agree on what
constitutes an end-of-line character. The textbox does indeed use Chr$(13) &
Chr$(10). The document wants to see only the Chr$(13), and it displays the
Chr$(10) as a square.

Try this call instead of the one you have:

Call find_replace_text("&buyers_name", _
Replace(frmInitialdata.txtbuyersname.Text, Chr$(10), ""))
 

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