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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing out last name 2

Status
Not open for further replies.

dbero

Technical User
Mar 31, 2005
109
US
I have a name field that has the full name, which may include a middle name. I need to isolate the last name. What I would like to do is to start from the right side and work left gathering the last name until a space. Is this the best way to accomplish culling the last name, and if so can you please help me with the code to do it?

THank you very much!
 
A starting point:
LastName=Mid(Trim(FullName),InStrRev(Trim(FullName)," ")+1)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Try this

Code:
Public Function MiddleName(FullName As String) As String
Dim TempName As String
Dim Names()  As String

' Reduce multiple Spaces to a Single Space
TempName = Trim$(FullName)
Do Until Len(TempName) = Len(Replace(TempName, "  ", " "))
   TempName = Replace(TempName, "  ", " ")
Loop

' Pull out the different Names
Names = Split(TempName, " ")

' Return the Middle name if there are 3 names found
If UBound(Names) = 2 Then
   MiddleName = Names(1)
Else
   MiddleName = ""
End If

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top