Remove part of string

J

JackpipE

I have First Name and Middle Name all in one field: |Jack Fred| - How
can I remove the middle name ie: Fred from this string? There could
also be just First Name or First Name and middle initial only.

Thanks,
Jack
 
S

Stefan Hoffmann

hi Jack,
I have First Name and Middle Name all in one field: |Jack Fred| - How
can I remove the middle name ie: Fred from this string? There could
also be just First Name or First Name and middle initial only.
Use InStr() and Left():

Public Function FirstWord(AString As String) As String

Dim SpacePos As Long

SpacePos = InStr(ASrting, " ")
If SpacePos > 0 Then
FirstWord = Left(AString, SpacePos)
Else
FirstWord = AString
End If

End Function

But I'm not sure if this works for all kind of names.


mfG
--> stefan <--
 
Top