Solved

Separate Name field

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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 …

821 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