theKruser
Registered User.
- Local time
- Today, 14:54
- Joined
- Aug 6, 2008
- Messages
- 122
I have a database output that I am trying to import into my database. I do not have access to the other database to create my own output. The database outputs name in format
Last name works just fine, so does middle initial. I don't know what I am doing wrong with the first name. It is the same code as last name used on a different variable.
Ends state, I just need to extract the names separately. If I am way off, or if there is a better way of doing it, I would love to learn what I am doing wrong.
Thank you in advance for taking the time to help me.
Last, First MI
(there are two spaces between the comma and the first name(no idea why) and always a trailing space after the first name, regardless of presence of middle initial). Here is what I have so far.Last name works just fine, so does middle initial. I don't know what I am doing wrong with the first name. It is the same code as last name used on a different variable.
Ends state, I just need to extract the names separately. If I am way off, or if there is a better way of doing it, I would love to learn what I am doing wrong.
Thank you in advance for taking the time to help me.
Code:
Public Function SplitName(strPart As String, strFullName As String) As String
On Error GoTo ErrorHandler
'Etracts names from a field with full name
Dim strNamePart As String
Dim strF As String
Dim strM As String
Dim strFM As String
strFM = Mid(strFullName, InStr(strFullName, " ") + 2) 'extracts everything right of the comma
strM =
Select Case strPart
Case "F"
strNamePart = Left(strFM, InStr(strFM, " ") - 1)
Case "M"
strNamePart = Right(strFullName, 1)
Case "L"
strNamePart = Left(strFullName, InStr(strFullName, ",") - 1)
End Select
SplitName = Trim(StrConv(strNamePart, 3))
ExitProcedure:
On Error Resume Next
Exit Function
ErrorHandler:
Call ErrHandler("basTools", 0, Err.Number, Err.Description)
Resume ExitProcedure
End Function