cgmarshall
Technical User
I have a function to parse names by space. However it John Doe has John in the Prefix field, Doe in the FN field.
Is there some code that will the parts go into the right fields.
Below is my function code.
Function CountSpaceWords(ByVal s) As Integer
' Counts the words in a string that are separated by commas.
Dim WC As Integer, Pos As Integer
If VarType(s) <> 8 Or Len(s) = 0 Then
CountSpaceWords = 0
Exit Function
End If
WC = 1
Pos = InStr(s, " ")
Do While Pos > 0
WC = WC + 1
Pos = InStr(Pos + 1, s, " ")
Loop
CountSpaceWords = WC
End Function
Function GetSpaceWord(ByVal s, Indx As Integer)
' Returns the nth word in a specific field.
Dim WC As Integer, Count As Integer, SPos As Integer, EPos As Integer
WC = CountSpaceWords(s)
If Indx < 1 Or Indx > WC Then
GetSpaceWord = Null
Exit Function
End If
Count = 1
SPos = 1
For Count = 2 To Indx
SPos = InStr(SPos, s, " ") + 1
Next Count
EPos = InStr(SPos, s, " ") - 1
If EPos <= 0 Then EPos = Len(s)
GetSpaceWord = Trim(Mid(s, SPos, EPos - SPos + 1))
End Function
Is there some code that will the parts go into the right fields.
Below is my function code.
Function CountSpaceWords(ByVal s) As Integer
' Counts the words in a string that are separated by commas.
Dim WC As Integer, Pos As Integer
If VarType(s) <> 8 Or Len(s) = 0 Then
CountSpaceWords = 0
Exit Function
End If
WC = 1
Pos = InStr(s, " ")
Do While Pos > 0
WC = WC + 1
Pos = InStr(Pos + 1, s, " ")
Loop
CountSpaceWords = WC
End Function
Function GetSpaceWord(ByVal s, Indx As Integer)
' Returns the nth word in a specific field.
Dim WC As Integer, Count As Integer, SPos As Integer, EPos As Integer
WC = CountSpaceWords(s)
If Indx < 1 Or Indx > WC Then
GetSpaceWord = Null
Exit Function
End If
Count = 1
SPos = 1
For Count = 2 To Indx
SPos = InStr(SPos, s, " ") + 1
Next Count
EPos = InStr(SPos, s, " ") - 1
If EPos <= 0 Then EPos = Len(s)
GetSpaceWord = Trim(Mid(s, SPos, EPos - SPos + 1))
End Function