Solved

Separate First Name - Middle Name - Last Name to three columns - ACCESS VBA SQL

Posted on 2014-03-13
9
2,528 Views
Last Modified: 2016-03-20
I have a table field of people names(full name) in an order of "First Name, Last Name Middle Name", I need to separate this field records to three separate columns like First Name Middle Name and Last Name. Can you please help me experts?

Sample Data
==========
Mayes,Taryn
McAdams,Carrie
McCandless,Rosemary Van Linde
McConkey,Morgan E
McCurdy,Jeanne C
0
Comment
Question by:gtmathewDallas
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 10

Expert Comment

by:etech0
ID: 39927552
Sounds like you'd need to use a combination of InStr, Left, Right, Mid, and Len functions. I can put it together for you later if you want, when I have access to a computer with Access.
0
 

Author Comment

by:gtmathewDallas
ID: 39927865
Thank you etechO
0
 
LVL 10

Accepted Solution

by:
etech0 earned 500 total points
ID: 39928160
Okay, here goes:

(Make a query with this SQL)
SELECT Table1.PersonsName, InStr([PersonsName],",") AS comma, Left([PersonsName],[comma]-1) AS LastName, IIf(InStr([comma],[personsname]," ")=0,Len([personsname])+1,InStr([comma],[personsname]," ")) AS FirstSpace, Mid([PersonsName],[comma]+1,[firstspace]-[comma]-1) AS FirstName, Mid([personsname],[firstspace]+1,Len([personsname])) AS MiddleName
FROM Table1;

Open in new window


Notes: Replace "Table1" with the name of the table we're looking at, and replace "PersonsName" with the name of the field with the name in it. The rest should stay the same. There will be a couple of columns in the query that you can ignore (they are used for calculations).

Let's see if this works!
0
 

Author Closing Comment

by:gtmathewDallas
ID: 39929319
Excellent etech0, Thank you so much
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 10

Expert Comment

by:etech0
ID: 39929352
My pleasure!
0
 

Expert Comment

by:Nancy Carpenter
ID: 40204257
I get #Func! when I try to run this query.  I am not sure how to fix this.  Can you help?

Thanks!
0
 

Expert Comment

by:Nancy Carpenter
ID: 40204272
I think I get the #Func! error in the LastName field because it is returning a null.  All my last names are in the MiddleName field.
0
 

Expert Comment

by:Nancy Carpenter
ID: 40204285
The other problem is that some of the MiddleName fields have both middle name and last name with 2 spaces in between.
0
 
LVL 1

Expert Comment

by:Mswetsky
ID: 41515171
was there a solution to this #Func!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

930 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now