BrockLanders
Programmer
Is there a way to remove not only leading and trailing spaces of text strings (Trim), but spaces in between words as well. I wanted to include it in the criteria of a field for a query.
Thanks
Thanks
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'Will replace every space with ... nothing
str = Replace(str, " ", "")
'Replace()
'
'Replaces any substring with any other substring.
Public Function Replace(ByRef originalString As String, ByRef textToReplace As String, _
ByRef replacementText As String)
Dim offset As Integer
If originalString = "" Then
Replace = ""
Else
offset = InStr(1, originalString, textToReplace, vbTextCompare)
If offset <= 0 Then
Replace = originalString
Else
Replace = Replace(Left(originalString, offset - 1), textToReplace, replacementText) & _
replacementText & _
Replace(Mid(originalString, offset + Len(textToReplace)), textToReplace, replacementText)
End If
End If
End Function