Need help with Access VBA script that can determine the last name by identifying space in the end and only retrieving the last name in the full name.
So as an example: if the full name is John W Ciesle - how can I use InStr or InStrRev to give me the last name only as a value?
If CountofCharacterInString(sFullName, " ") = 2 And sFullName Like "* *" Then
'grab everything from space backward
'Stop
sFullName = Right$(sFullName, Len(sFullName) - InStrRev(sFullName, " "))
GoTo Exit_Proc
End If
Public Function CountofCharacterInString(sValue As String, sCharacter As String) As Long
On Error GoTo Err_Proc
Dim lCount As Long
lCount = Len(sValue) - Len(Replace(sValue, sCharacter, ""))
Exit_Proc:
CountofCharacterInString = lCount
Exit Function
Err_Proc:
Call LogError(Err, Err.Description, "sys_mTasks @ CountofCharacterInString")
Resume Exit_Proc
End Function
Dim arrNames() as string
arrNames = Split(Replace(FullName, " ", " "), " ")
LastName = arrNames(ubound(arrnames))
I've included a Replace() function in there to replace instances where there are multiple consecutive spaces (not uncommon with text strings) with a single space. Then use the Split() function to split the FullName into its parts, then select the last element of the array.
HTH