Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Separate Name field

Posted on 2006-11-15
Medium Priority
261 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
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

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.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
###### Suggested Courses
Course of the Month7 days, 11 hours left to enroll