madelca100
MIS
re archived thread705-1042294
Added a test for Null values.
Public Function ReplaceinString(strSearch As Variant,
strFind As String, strReplace As String) As Variant
'Description - Finds and replaces a string in a string by another string
'Author - Neil Gummow
' Modified - Mike Adel 11/22/2005 - add a test for Null
'System - Access
' Example - replaceinstring("300-06", "-", "") = 30006
Dim intCounter As Integer
If IsNull(strSearch) Then
ReplaceinString = ""
Else
For intCounter = 1 To Len(strSearch)
If Mid(strSearch, intCounter, Len(strFind)) = strFind Then
strSearch = Left(strSearch, intCounter - 1) & strReplace & Mid(strSearch, intCounter + Len(strFind))
End If
Next intCounter
ReplaceinString = strSearch
End If
End Function
Added a test for Null values.
Public Function ReplaceinString(strSearch As Variant,
strFind As String, strReplace As String) As Variant
'Description - Finds and replaces a string in a string by another string
'Author - Neil Gummow
' Modified - Mike Adel 11/22/2005 - add a test for Null
'System - Access
' Example - replaceinstring("300-06", "-", "") = 30006
Dim intCounter As Integer
If IsNull(strSearch) Then
ReplaceinString = ""
Else
For intCounter = 1 To Len(strSearch)
If Mid(strSearch, intCounter, Len(strFind)) = strFind Then
strSearch = Left(strSearch, intCounter - 1) & strReplace & Mid(strSearch, intCounter + Len(strFind))
End If
Next intCounter
ReplaceinString = strSearch
End If
End Function