Solved

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

Posted on 2003-11-03
6
2,278 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
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.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
View vs Edit mode enhancements 12 40
Run Time Error 3075 15 44
MS Access - update query inner join will not work with long text field 11 15
append to an ms access field 6 24
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

910 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

23 Experts available now in Live!

Get 1:1 Help Now