that needs to be written out to a text file that will then be imported or used
by another application such as Crystal Reports or Excel. When writing
information to a text file using the Write# command, fields are automatically
separated by commas and enclosed with double quotes. If there are double
quotes within one these fields, the record is usually not imported properly.
This script replaces the double quotes with two single quotes, thus allowing
the records to be imported.
Function ReplaceDoubleQuotes(x As String) As String
Dim pos As Long
Dim doublequote As String
Dim twosinglequotes As String
pos = 1
doublequote = """"
twosinglequotes = "''"
Do Until pos = 0
L = Len(x) ' Get the length of the whole string
pos& = Instr(1, x, doublequote) ' find the doublequotes
If pos <> 0 Then
P1 = Left(x,pos - 1) ' Part 1 of the text string
P2 = Right(x,L- pos ) ' Part 2 of the text string (determined
by subtracting the current pos from the total length of the string
X = P1 & twosinglequotes & P2 ' combine part 1 with 2 single
quotes and then add part 2
replacedoublequotes = X