Solved

How to split last, first and middle name from Name field?

Posted on 2003-11-03
6
2,256 Views
Last Modified: 2012-06-27
Hi,
In my table I have a field called "Name" and the field look like this:

Name
Lamphere, Justin C
Vazquez Cortez, Fernando
Thompson, Chennea S
Her, Mai

Is it possible to separate them and create 3 columns, one for last, one for first and the other for middle name.

The output table will look like this:
Name                                   last                        first         middle
Lamphere, Justin C                Lamphere             Justin         C
Vazquez Cortez, Fernando      Vazquez Cortez    Fernando
Thompson, Chennea S            Thompson           Chennea      S
Her, Mai                                  Her                     Mai

I there a way to separate this field to 3 columns above. Thanks.

     

0
Comment
Question by:sgrahman
6 Comments
 

Accepted Solution

by:
tdkeller earned 75 total points
ID: 9673997
Check out this MS site Sample Expressions to Extract a Portion of a String or Text:

http://support.microsoft.com/default.aspx?scid=kb;en-us;286238&Product=acc2002

it gives you exactly what you need.

Tina
0
 
LVL 2

Expert Comment

by:thorkyl
ID: 9674406
yes you will need some code

public function tkb_SPLIT_NAME()
    dim db as database
    dim rs as dao.recordset
    dim sLAST as string
    dim sFIRST as string
    dim sMI as string
    dim sNAME as string
    set db = currentdb
    set rs = db.openrecordset("SELECT [NAME] FROM TBL_NAMES")
    while not rs.eof
        sNAME = rs!NAME
        sLAST = left(sNAME,instr(1,sNAME,",")-1) 'get the last name
        sNAME = trim(right(sNAME,len(sNAME)-1) 'drop the comma and the space
        if instr(1,trim(sNAME)," ")>0 then 'we have a MI
            sFIRST = left(sNAME,instr(1,sNAME," ") 'get the first name
            sNAME = trim(right(sNAME,len(sNAME)) 'drop the space
            sMI = sNAME
        else
            sFIRST = Trim(sNAME) 'No MI
            sMI=""
        end if
        rs.edit
            rs!LNAME = trim(sLAST)
            rs!FNAME = trim(sFIRST)
            rs!MNAME = trim(sMI)
        rs.update
        rs.movenext
    wend
end function


Should do it for you
0
 

Author Comment

by:sgrahman
ID: 9674627
hi thorkyl,
Where exactly am i supposed to be adding this code to? I inserted this code to module but it is not working. thx.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Expert Comment

by:tdkeller
ID: 9674780
use the expressions in my previous response in an update query.  Add FName, LName, MI to the table so they can be updated from Name.
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9676868
Ok, I will stick to the query type solution:

step:
1.   Create a table with field: Names, First, Middle, Last (in table 1)
2.   Paste your data into Names
3.   Create a new query in design mode
4.   Add table1 to the query
5.   From menu query, select update query
Now, we will create the query for first name
6.   in the input grid, select field->First
7.   in the Update To clause->Right(Trim([Names]),Len(Trim([Names]))-InStr(1,[Names]," "))
8.   Save and run the query, accept all the warning and continue to finish,
9.   Your result is shown in the column [first] of table1

Continue to other fields with Update To:
Refer here for update to clause
http://support.microsoft.com/default.aspx?scid=kb;EN-US;286238

~ fantasy ~



0
 
LVL 2

Expert Comment

by:thorkyl
ID: 9678600
If you place the code in a module
then just run the code ( F5 key )

You will need to change the line

 set rs = db.openrecordset("SELECT [NAME] FROM TBL_NAMES")

TO

 set rs = db.openrecordset("SELECT * FROM TBL_NAMES")

My sample taks the presumption that you added the new fields to the existing table
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

22 Experts available now in Live!

Get 1:1 Help Now