Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run a Query to separate names from one field to two

Status
Not open for further replies.

RAxel

MIS
Sep 8, 2005
121
US
Basically I have one field in excel that I've imported into Access, called 'Name'. In it, looks like this:

Name
dover, ben
last, first
name, fake
etc....

Basically, it's last name, first name in the column. I want to separate them into two fields, one with first name and the other with last name with no comma. Is this possible to do in Access (without the help from a programming language, like .NET)

I want:
Last Name First Name
Dover Ben
Last First
Name Fake

Thanks.
 
Short answer ... yes ... it is possible. Access however has at least two "languages" (SQL and VB) that it uses. Which do you want to use?

In SQL
Code:
Select Left([Name], Instr([Name],",")-1) As LastName,
       Mid ([Name], Instr([Name]," ")+1) As FirstName
From .... etc. ...

In VB
Code:
Dim FirstName As String
Dim LastName  As String
Dim rs As DAO.Recordset
Set rs = Currentdb.OpenRecordset ("Select [Name] From tbl")
Do Until rs.EOF
   FirstName = Mid (rs![Name], Instr(rs![Name]," ")+1)
   LastName  = Left(rs![Name], Instr(rs![Name],",")-1)
   Debug.Print FirstName & " " & LastName
   rs.MoveNext
Loop
 
Thanks a bunch Golom. Do you know of any good books to read through (or purchase) to help out with SQL problems, like this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top