x
Solved

# Separate Name field

Posted on 2006-11-15
Medium Priority
267 Views
I have an imported database with txtName which is Last, First and Middle and other fields.  How is the best way to split the Name into three fields such as:
Name: Boyd, Peter B.
into
LastName: Boyd
FirstName: Peter
MiddleInitial: B
0
Question by:zubin6220

LVL 16

Accepted Solution

GreymanMSC earned 400 total points
ID: 17953912
Are you using Access 2002 or onwards?  If so, the Strings.Split(...) function should help.

Public Function fnSplitName(Fullname As String) As Variant
Dim V As Variant
If Strings.InStr(1, Fullname, ",") > 0 Then
'Assume FullName entered in Surname, FirstName Initials order.
V = Strings.Split(Fullname, " ", 3)
If UBound(V) - LBound(V) = 2 Then
fnSplitName = Array(V(LBound(V)), V(LBound(V) + 1), V(LBound(V) + 2))
ElseIf UBound(V) - LBound(V) = 1 Then
fnSplitName = Array(V(LBound(V)), V(LBound(V) + 1))
Else
fnSplitName = Array(V(LBound(V)))
End If
Else
'Assume FullName entered in FirstName Initials Surname order.
V = Strings.Split(Fullname, " ", 3)
If UBound(V) - LBound(V) = 2 Then
fnSplitName = Array(V(LBound(V) + 2), V(LBound(V)), V(LBound(V) + 1))
ElseIf UBound(V) - LBound(V) = 1 Then
fnSplitName = Array(V(LBound(V) + 1), V(LBound(V)))
Else
fnSplitName = Array(V(LBound(V)))
End If
End If
End Function

Public Function fnFirstName(Fullname As String) As String
Dim V As Variant
V = fnSplitName(Fullname)
If UBound(V) - LBound(V) >= 1 Then
fnFirstName = V(LBound(V) + 1)
Else
fnFirstName = ""
End If
End Function
0

LVL 19

Assisted Solution

Limbeck earned 100 total points
ID: 17953950
hm i usually export tables like this to excel, use formula's to split and manually correct the results (there are always typos in tables like this that give back faulty results when processing it in a query ) and import it back into the db

good luck

Ed
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.