Solved

Separate Name field

Posted on 2006-11-15
2
230 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
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now