Results 1 to 5 of 5
  1. #1
    JohnnyMizchief is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    3

    Accurately splitting up LastName, FirstName from a Sharepoint Link into a Query

    Hell Everyone, I've searched far and wide for a fix for this. I'm not a Dev or programming Guru, but I'm fascinated with the advancements of Access 2010. Anyways, to make a long story short. I'm trying to separate LastName, FirstName into separate fields : FirstName and LastName. The code I have is working for the most part. But I had to create a separate query with the replace statement to get rid of the ","... Looking at the data now, I had people with names like Mac Buren, Tony and I'm only picking up the Mac part in my query. Help?



    Code:
    SELECT Left([Employee Name],InStr([Employee Name]," ")) AS qryLastName, Right([Employee Name],Len([Employee Name])-InStrRev([Employee Name]," ")) AS [First Name], Employees.*
    FROM Employees
    ORDER BY Left([Employee Name],InStr([Employee Name]," "));

  2. #2
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Instead of using the blank as the separator, use the comma but don't include it in the data:

    SELECT Left([Employee Name],InStr([Employee Name],",")-1) AS qryLastName,
    mid([Employee Name],InStr([Employee Name],",")+1) AS [First Name], Employees.*
    FROM Employees
    ORDER BY Left([Employee Name],InStr([Employee Name],",")-1);

    The +1 and -1 ensure that the comma is not included in the query results. Be aware that this solution will cause an error if you get a situation where there is no comma in [Employee Name]

    John

  3. #3
    JohnnyMizchief is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    3

    Talking Resolved

    Quote Originally Posted by John_G View Post
    Hi -

    Instead of using the blank as the separator, use the comma but don't include it in the data:

    SELECT Left([Employee Name],InStr([Employee Name],",")-1) AS qryLastName,
    mid([Employee Name],InStr([Employee Name],",")+1) AS [First Name], Employees.*
    FROM Employees
    ORDER BY Left([Employee Name],InStr([Employee Name],",")-1);

    The +1 and -1 ensure that the comma is not included in the query results. Be aware that this solution will cause an error if you get a situation where there is no comma in [Employee Name]

    John
    Thanks John G!!!! That actually worked. But for some reason I'm getting a blank space before the first name? I can deal with that easily enough. But the table is pulling the first and last names with 100% accuracy though. THANK YOU SO MUCH!

  4. #4
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Glad it worked. The leading blank on the first name is because a blank is the first character following the comma.
    Using the TRIM function should fix it:

    trim(mid([Employee Name],InStr([Employee Name],",")+1))

    John

  5. #5
    JohnnyMizchief is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2012
    Posts
    3
    It fixed it. Now onward to my assett form creation!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 05-08-2012, 03:20 PM
  2. Link Access Query to Sharepoint List
    By mlm in forum SharePoint
    Replies: 0
    Last Post: 04-24-2012, 03:06 PM
  3. Replies: 4
    Last Post: 09-06-2011, 01:00 AM
  4. FirstName + LastName
    By mehulkar in forum Access
    Replies: 1
    Last Post: 07-28-2011, 01:40 PM
  5. Concatenate firstname + lastname
    By Dega in forum Access
    Replies: 2
    Last Post: 08-11-2010, 04:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums