Option Explicit
Option Compare Text
[color=green]' Change this line to something else for later versions.[/color]
#Const conAccessVersion = "Access97"
[color=green]' Comment out some code so the compiler doesn't laugh.[/color]
#If False Then
Option Non Explicit
Option Compare Widgets
This code = ful of erors, full of erors, ful of erors.
Bugger... this code is not good.
Come to think of it I actually like writing code like this.
#End If
Sub fred()
MsgBox Replace("Fred *", "*", "who?")
End Sub
#If conAccessVersion = "Access97" Then
[color=green]' Access97 does not have a Replace function.[/color]
Function Replace(ByVal strThisString As String, _
ByVal strSearchValue As String, _
ByVal strReplacement As Variant, _
Optional ByVal vntUnknown1 As Variant, _
Optional ByVal vntUnknown2 As Variant, _
Optional ByVal vntCompare As Variant = vbTextCompare) As String
Dim lngI As Long
Dim strLeftTemp As String
Dim strRightTemp As String
LookForNext:
lngI = InStr(1, strThisString, strSearchValue, vntCompare)
If lngI <> 0 Then
strLeftTemp = Left(strThisString, lngI - 1)
strRightTemp = Right(strThisString, Len(strThisString) - lngI - Len(strSearchValue) + 1)
strThisString = strLeftTemp & strReplacement & strRightTemp
GoTo LookForNext
End If
Replace = strThisString
End Function
#Else
[color=green]' Use the later version.[/color]
#End If