I have a function that is run as part of a query for scrubbing addresses in order to eliminate duplicates. To help find dups I get rid of things like ST and RD because they are not always included in the address. I thought it was working but noticed that in some cases, and I can't figure out why, it does not.
Here is one of my functions:
Public Function ScrubAddress(ByVal strfield As String) As String
If strfield <> "" Then
strfield = Replace(strfield, " ST ", " ")
strfield = Replace(strfield, " DR ", " ")
strfield = Replace(strfield, " RD ", " ")
strfield = Replace(strfield, " Ave ", " ")
strfield = Replace(strfield, " ", " ") ' Remove 10 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 9 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 8 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 7 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 6 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 5 spaces
strfield = Replace(strfield, " ", " ") ' Remove 4 spaces
strfield = Replace(strfield, " ", " ") ' Remove 3 spaces
strfield = Replace(strfield, " ", " ") ' Remove 2 spaces
strfield = Trim(strfield) 'Trim leading and trailing spaces
ScrubAddress = strfield
Else
ScrubAddress = ""
End If
End Function
It is suppose to find and remove all the ST and other items but I still find them exactly as I have defined them (with a leading and trailing space to make sure it's not part of a larger string).
I have tried everything I could think of, searched google, and this forum with no luck. Hopefully some one can help me out.
Here is one of my functions:
Public Function ScrubAddress(ByVal strfield As String) As String
If strfield <> "" Then
strfield = Replace(strfield, " ST ", " ")
strfield = Replace(strfield, " DR ", " ")
strfield = Replace(strfield, " RD ", " ")
strfield = Replace(strfield, " Ave ", " ")
strfield = Replace(strfield, " ", " ") ' Remove 10 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 9 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 8 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 7 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 6 Spaces
strfield = Replace(strfield, " ", " ") ' Remove 5 spaces
strfield = Replace(strfield, " ", " ") ' Remove 4 spaces
strfield = Replace(strfield, " ", " ") ' Remove 3 spaces
strfield = Replace(strfield, " ", " ") ' Remove 2 spaces
strfield = Trim(strfield) 'Trim leading and trailing spaces
ScrubAddress = strfield
Else
ScrubAddress = ""
End If
End Function
It is suppose to find and remove all the ST and other items but I still find them exactly as I have defined them (with a leading and trailing space to make sure it's not part of a larger string).
I have tried everything I could think of, searched google, and this forum with no luck. Hopefully some one can help me out.