splitting text fild

  • Thread starter Michael Lindekugel
  • Start date
M

Michael Lindekugel

Hello,

I have a table with a field called Name. the values in the Name field
consist of first names and last names separated by a space. the values vary
in length. I am having trouble finding a function or combination of
functions that allows me to split the field into two new fields of FirstName
and LastName. any suggestions?

cheers,
Michael
 
C

Cheryl Fischer

You can use the following expressions to get separate first names and last
names. Each involves looking for the position of a *single* space in the
FullName field:

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

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

This will work properly if all of your FullNames consist of a single first
name and a single last name separated by a space. It will return incorrect
results for names like:

Mary Anne Smith
John P. Van den Berg

hth,
 
F

fredg

Hello,

I have a table with a field called Name. the values in the Name field
consist of first names and last names separated by a space. the values vary
in length. I am having trouble finding a function or combination of
functions that allows me to split the field into two new fields of FirstName
and LastName. any suggestions?

cheers,
Michael

Michael,
If in fact the name of this field is [Name], I would strongly suggest
you change it to something else. Name is a reserved Access/VBA key
word. For more information read Microsoft KnowledgeBase article:
109312 'Reserved Words in Microsoft Access'
209187 'Acc2000: 'Reserved Words in Microsoft Access'
286335 'ACC2002: Reserved Words in Microsoft Access'

To answer your question, it is important that ALL the records be in
the same format. If it is in
FirstName space LastName
order, then:

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

But change that [Name] field name now!!!
 

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