I need a function to pick out different parts of names. I don't have a lot of time here at work. If anyone has time, I REALLY would love your help.
This is the way names can come when I read in the data:
Jones, Jeffrey S
Means Marilyn
Lawson Jay D
Lopez, Manuel B.
Lowe Jr Sam D
Smith III Trevor L
The function I have now is far from perfect. I REALLY could use your help. I was thinking of measuing the length of the variable and by what length it was, I would use a different thing. Well, this is what I have so far:
VB Code:
Function LastName(ByVal WholeName As String) As String Dim arr() As String Dim LName, index As String WholeName = Replace(WholeName, ",", " ") arr = Split(WholeName, " ") index = WholeName.IndexOf(" ") If index = -1 Then LName = "" Else If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then Try LName = arr(0) + " " + arr(1) Catch ex As Exception LName = "" End Try Else Try LName = arr(0) Catch ex As Exception LName = "" End Try End If End If Return Trim(LName) End Function Function FirstName(ByVal WholeName As String) As String Dim arr() As String Dim FName As String Dim index As Integer WholeName = Replace(WholeName, ",", " ") arr = Split(WholeName, " ") index = WholeName.IndexOf(" ") If index = -1 Then FName = "" Else If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then Try FName = arr(2) Catch ex As Exception FName = "" End Try Else Try FName = arr(1) Catch ex As Exception FName = "" End Try End If End If Return Trim(FName) End Function Function MiddleName(ByVal WholeName As String) As String Dim arr() As String Dim MName, index As String WholeName = Replace(WholeName, ",", " ") arr = Split(WholeName, " ") index = WholeName.IndexOf(" ") If index = -1 Then MName = "" Else If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then Try MName = " " + arr(3) Catch ex As Exception MName = "" End Try Else Try MName = " " + arr(2) Catch ex As Exception MName = "" End Try End If End If Return MName End Function
PLEASE HELP! Thanks!
Brenda




Reply With Quote