split names in into 2 fields in access

G

Guest

I have a name field that has the complete name in it. I need to seperate it
into a FirstName and LastName fields. The names are entered with space
between names, in the following format: firstname lastname. The problem I am
having is when the first name comprises of two names . Example mary kate
olsen. I can't figure out how to put "mary kate" into the firstname field.
I end up with
FirstName lastName
Mary kate olsen

I tring this in an update query using the following
LastName:
LTrim(Right$([TransPatient],Len([TransPatient])-InStr([TransPatient]," ")+1))

FirstName: Left([transpatient],InStr([transpatient]," ")-1)

I am using Access 2003.

Thank you for your help,
Harry
 
F

fredg

I have a name field that has the complete name in it. I need to seperate it
into a FirstName and LastName fields. The names are entered with space
between names, in the following format: firstname lastname. The problem I am
having is when the first name comprises of two names . Example mary kate
olsen. I can't figure out how to put "mary kate" into the firstname field.
I end up with
FirstName lastName
Mary kate olsen

I tring this in an update query using the following
LastName:
LTrim(Right$([TransPatient],Len([TransPatient])-InStr([TransPatient]," ")+1))

FirstName: Left([transpatient],InStr([transpatient]," ")-1)

I am using Access 2003.

Thank you for your help,
Harry

You're going to have a problem now matter how you do it.
If the names were simply like John Smith, it would be easy enough:

FirstName:Left([FullName],InStr([FullName]," ")-1)
LastName:Mid([FullName],InStr([FullName]," ")+1)

However, as you have discovered, many people use 2 first names, John
David Smith. Others have more than one space in their Last Name. Jan
van den Steen.

One alternative is to manually go through your records and replace the
space between first and last name with a comma, i.e. John David,Smith
or Jan,van den Steen.

Then use
FirstName:Left([FullName],InStr([FullName],",")-1)
LastName:Mid([FullName],InStr([FullName],",")+1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top