Solved

Separate Name field

Posted on 2006-11-15
2
256 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
[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
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
GreymanMSC earned 100 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

by:Limbeck
Limbeck earned 25 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

617 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