Solved

Separate Name field

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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 …

810 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