Solved

Separate Name field

Posted on 2006-11-15
2
220 Views
Last Modified: 2008-03-17
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
Comment
Question by:zubin6220
2 Comments
 
LVL 16

Accepted Solution

by:
GreymanMSC earned 100 total points
Comment Utility
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

by:Limbeck
Limbeck earned 25 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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 …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now