RE: Replace function and carriage returns

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



To: Steven M

Hi Steven,

I am working on an issue that is indirectly related to Bz's issue. I am
trying to import the contents of a .txt file into an MS Access table through
VBA. The file is pipe delimited, and I have been able to successfully place
the delimited values into their corresponding fields within the first row of
the destination table. What I cannot figure out is how to take the last
value of the first row, which contains the carriage return, and begin
populating the second row of the destination table with the values to the
immediate right of the carriage return.

Any thoughts?

Regards,

Mike



"StevenM" wrote:

To: Bz,

Perhaps you need something like:

'****
'*
'* Function: StripCr
'*
'* When a string ends with a "Carriage Return" marker, or a "Carriage Return"
'* and "Line Feed" markers, this function will strip them off from a string.
'*
'****
Function StripCr(ByVal sStr As String) As String
Dim nPos As Long
nPos = InStr(sStr, Chr(13))
If nPos > 0 Then
sStr = Left(sStr, nPos - 1)
End If
StripCr = sStr
End Function

Steven Craig Miller

"bz" wrote:

I am using Word 2000 and XP.

I have a table containing formfields. In a macro I output the contents of
selected formfields to a text file and then later insert this file into a new
Word document and use the text to table conversion to create a table.
Sometimes, if one of the formfields contains carriage returns, the result is
that the text following the carriage return begins on the first column of the
next row (i.e. not the next line in the same cell).

The best solution would be to have the carriage returns work correctly
(within the same cell).

An alternative is to strip out the carriage returns. I tried doing this
using the Replace function. Before writing out to the text file, I copy the
.result of the formfield to a string
(myString=ActiveDocument.FormFields("myString").Result).
I then try to replace: myString=Replace(myString,"^p",""). Also tried with
myString=Replace(myString,Chr(13),"").

The result is that no replacement is made. This is the case no matter what
I try to use as a replacement string.

Thanks in advance for any help, bz
.



Relevant Pages

  • RE: Replace function and carriage returns
    ... Function StripCr(ByVal sStr As String) As String ... Dim nPos As Long ... I have a table containing formfields. ... Sometimes, if one of the formfields contains carriage returns, the result is ...
    (microsoft.public.word.vba.general)
  • RE: Replace function and carriage returns
    ... Function StripCr(ByVal sStr As String) As String ... Dim nPos As Long ... Sometimes, if one of the formfields contains carriage returns, the result is ...
    (microsoft.public.word.vba.general)
  • Re: trouble with string replace
    ... string literal, when it looks like what you wanted was a regular expression literal. ... Although - replace - will convert string arguments into regular expression literal it will use the string as the pattern that will be matched, so will be trying to match something that ends - /g -, which isn't going to be a carriage return. ... The values returned by - innerHTML - are a serialisation of the the DOM, and DOMs represent as post HTML parsing interpretation of a document. ... Series of whitespace characters can act as a single white space character or thay can be ignored completely. ...
    (comp.lang.javascript)
  • Re: string functions
    ... sometimes it might have more than one carriage return like it is shown in your example. ... So, your display of the starting string and the result you wanted clearly showed a starting sring with spaces and a result with carriage returns, or a series of individual values, quite the opposite of what you have just asked for in this new message of yours. ... The next job the code does is to analyze that string in a small loop and display the Ascii code of each character in a listBox, together with the character each of those Ascii codes represents. ...
    (microsoft.public.vb.general.discussion)
  • Re: Replace function and carriage returns
    ... By "second row of the destination table" do you mean the second ... immediate right of the carriage return. ... Function StripCr(ByVal sStr As String) As String ...
    (microsoft.public.word.vba.general)