Split a field based on first occuring space from left and . . .


I have a field where I want to extract the all characters that are left of the first occurring space.  But I also want to extract the characters if there is no space in the field.

So for example.  I have created a field that I call, "FirstPart"  In it I want information taken from a field called "First":

Field: First
Record 1: Jim K.
Record 2: Susan

When I run an update query to the FirstPart field; Left([First],InStr([First]," ")-1)

I get:

Field: FirstPart
Record 1: Jim K.
Record 2: (blank)

I experimented with used Mid and Instrrev, but not getting any results.  That would be due to my inexperience in using those functions.

Any thoughts?


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeffrey CoachmanMIS LiasonCommented:
Questions like these are typically dependent on being able to handle each and every data entry inconsistency.

What is there is no name? (blank, Null)
What if there is no space.
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
You want:

IIF(Instr([First]," ")>0,Left([First],InStr([First]," ")-1),[First])


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rey Obrero (Capricorn1)Commented:
try this
Update tableName
Set [FirstPart]=Left([First] &" ",InStr([First] & " "," ")-1)
ListriteAuthor Commented:
Thanks Jim and Capricorn,

Tried both solutions and they worked great.  So with that in mind, couldn't really choose which to select as the "Best Solution"

boag2000: Thanks for your reply.  The only requirement I had was to retrieve information in records that had information in the First field.  So any nulls, blanks, did not matter in this case.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.