Here is a function that works with Access to simulate the built in VB Replace function. For those of you have have trouble with recursion, this function does not use it which makes it easier to understand.
It also allows you to set the string comparison method. The compare argument can be omitted, or it can be 0 or 1. Specify 0 (default) to perform a binary comparison. Specify 1 to perform a textual, noncase-sensitive comparison.
Public Function Replace(sString As Variant _
, sFind As String _
, sReplace As String _
, Optional iCompare As Long = vbBinaryCompare)
_ As Variant
Dim iStart As Integer, iLength As Integer
If IsNull(sString) Then
Replace = Null
Else
iStart = InStr(1, sString, sFind, iCompare)
Do While iStart > 0
sString = Left(sString, iStart - 1) _
& sReplace & Mid(sString, iStart + Len(sFind), Len(sString) - iStart - Len(sFind) + 1)
iStart = InStr(iStart, sString, sFind)
Loop
Replace = sString
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.