General information
Category:
Coding, syntax & commands
I'm at home (have to stop answering questions from home) with neither VB nor Access, so my code might be shaky but we'll try. As VBA has no Replace function all you can do is loop through the string and create the new string on the fly. Below i example code:
Public Function MakeNewString (InputString as String) as string
Dim sQuote As String, sDQuote As String
dim CurrentStringPos as long
dim LastStringPos as long
dim TempOutputString as string
MakeNewString = ""
LastStringPos = 0
sDQuote = Chr$(34)
sQuote = Chr$(39) & Chr$(39)
do while CurrentStringPos = instr(LastStringPos + 1, InputString, sDQuote)
TempOutputString = Mid$(InputString, LastStringPos + 1, CurrentStringPos _
- 1) & sQuote
MakeNewString = MakeNewString & TempOutputString
LastStringPos = CurrentStringPos + 1
loop
TempOutputString = Mid$(InputString, LastStringPos + 1)
MakeNewString = MakeNewString & TempOutputString
End function
Essentially, the code starts at the first char of the string and uses a boolean test of the instr function to determine if there are anymore "'s in the string. If there are it uses the mid$ to grab everything to the left of it, adds the '' and then resets the Pos counters to start searching the string again on the character to the right of the ". The final step is to grab everything from the right of the last " to complete the new string. One quick additional note: I tend to use a lot of variables and explicit assignments in my sample code. This code can be done more efficiently but I prefer to show things very detailed and explicity in sample code. Like I said, I couldn't test this at home but it should be fairly sound (provided I haven't made too many typos!).
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only