i just need a few more detail about this FAQ posting:
Function ReplaceString(ByVal SourceString As String, ByVal OriginalString As String, ByVal NewString As String) As String
'Recursive function ReplaceString searches Source string and replaces ALL OCCURRENCES of OriginalString with NewString.
'If a value for NewString is ommitted (or IsEmpty), then all occurrences of OriginalString are removed from the SourceString!
Dim Position As Integer
If SourceString = "" Or IsNull(SourceString) Then
ReplaceString = SourceString
Else
Position = InStr(1, SourceString, OriginalString)
If Position > 0 Then
ReplaceString = (Mid$(SourceString, 1, Position - 1) & NewString & ReplaceString(Mid(SourceString, Position + Len(OriginalString)), OriginalString, NewString))
Else
ReplaceString = SourceString
End If
End If
End Function
If i have a table called AddressP and a field called ADDRESS_1 and wanted to search the word Avenue and replace it it with Ave using VBA( Code Above) what do i need to change. really confused on what to change to the sample code for it to work.
And is it possible to use Private Sub instead of a function. . . really don't understand how to use the function. . Private sub you just run it from the module and it runs. . . but when you run a function in the module. . what do you need to do to run it. . .
thanks
erwin
Function ReplaceString(ByVal SourceString As String, ByVal OriginalString As String, ByVal NewString As String) As String
'Recursive function ReplaceString searches Source string and replaces ALL OCCURRENCES of OriginalString with NewString.
'If a value for NewString is ommitted (or IsEmpty), then all occurrences of OriginalString are removed from the SourceString!
Dim Position As Integer
If SourceString = "" Or IsNull(SourceString) Then
ReplaceString = SourceString
Else
Position = InStr(1, SourceString, OriginalString)
If Position > 0 Then
ReplaceString = (Mid$(SourceString, 1, Position - 1) & NewString & ReplaceString(Mid(SourceString, Position + Len(OriginalString)), OriginalString, NewString))
Else
ReplaceString = SourceString
End If
End If
End Function
If i have a table called AddressP and a field called ADDRESS_1 and wanted to search the word Avenue and replace it it with Ave using VBA( Code Above) what do i need to change. really confused on what to change to the sample code for it to work.
And is it possible to use Private Sub instead of a function. . . really don't understand how to use the function. . Private sub you just run it from the module and it runs. . . but when you run a function in the module. . what do you need to do to run it. . .
thanks
erwin