Solved

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

Posted on 2003-11-03
6
2,307 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

860 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