Solved

Statement to split out first and last name in query

Posted on 2014-01-09
4
504 Views
Last Modified: 2014-01-09
Hello.  I have a field that has a persons first and last name formatted like this  
LASTNAME, FIRSTNAME

I need to split them out into to fields in my query.

So - how do I get everything BEFORE the comma in one cell.... and everything AFTER the comma in another cell?  also I would like everything after the comma not to have a space between , Firstname.

Thanks
0
Comment
Question by:joylene6
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39769225
You can use the split function after retrieving from the query:

dim arr as variant

arr = Split(YourString, ",")

That being said, a much better (and easier) Database design would be to define separate columns for first name and last name.   That way you can join them easily in any manner you need to.

You should never combine more than one object (such as first and last name) into a single column.

A similar design should also apply to addresses.  you would not want to make one field called address and then store all of street address, city, state, zip all in the one field.  You should make a separate column for each of them.
0
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39769233
You can use the LEFT and MID functions along with the INSTR function to do this.
Use Instr to find the position of the comma and use that value (minus 1) as the second value to LEFT. Use the same technique with MID, but subtract the position value from the length (LEN) of the string.

It would look something like:
LASTNAME: Left([name],InStr([name],",")-1)
FIRSTNAME: Mid([name], Instr(1, [name], ", ") + 2)
0
 
LVL 1

Author Comment

by:joylene6
ID: 39769249
Thanks will give it a try
0
 
LVL 1

Author Comment

by:joylene6
ID: 39769612
Shaun Kline - thanks that worked!

Ken - the database had information in it that I could not change and did not create, but yes I totally agree with you

Thanks
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

749 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