Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding a position of a space in a string 2

Status
Not open for further replies.

ninash

Technical User
Jul 6, 2001
163
0
0
GB
Can anyone tell me how to find the positioon of a space using VBA or VB5 in Access97.
Please help I need this information to finish a project
 
MyStr = "this is a typical String"
? InStr(MyStr, " ")
5
MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Sorry I also need to find its location as my string will only have 1 space in it
 
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

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top