Ok you have an answer to the question of how to find a space in a string. Once you have found it, you normally want to do something based on that information.
This is a piece of code I have written to strip off a word from the start of a string. I have some others that takes the end, middle, and also splits a long field over 2 fields if they would be usefull to you.
Cheers
Norm
Function FirstWord(SearchString As String) As String
Dim SearchChar As String
Dim MyPos As Integer
SearchChar = " "
' Useful for stripping off the first name or title from an address
' Test to see if a space exists in the field (SearchString)
' If a space character exists the part before the space is
' returned as the FirstWord
' If not found the the whole field is returned
' vbTextCompare is NOT Case Sensitive
' vbBinaryCompare IS Case Sensitive
If InStr(1, SearchString, SearchChar, vbTextCompare) = Null _
Or InStr(1, SearchString, SearchChar) = 0 Then
FirstWord = SearchString
Else
MyPos = InStr(1, SearchString, SearchChar, vbTextCompare)
FirstWord = Left(SearchString, MyPos)
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.