Results 1 to 5 of 5
  1. #1
    genemd is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    2

    Manipulating text string

    I am new to Access and have imported data into a table which has a field named employee. All of the data in the employee field is in the last name,first name, middle initial format, e.g., Brown,Thomas R. I want to either create a new field, or update the current employee field in the format of Thomas R Brown. Any help would be appreciated.

  2. #2
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    use a query and the Left, Right, Mid, and/or Instr functions. In your example you would parse the name out based on the location of the comma and the space. The only trick to it is if the data format is ever in a different format than the one you listed.

    Examples:

    Left([Name], Instr([Name], ",")) will get you the last name (if I have done it correctly)

    Mid([Name], Instr([Name], ", "), Instr([Name]," ")) should get you the first name (plus or minus 1 space

    Right([Name], 2) - should get you the middle initial give or take a few spaces.

    Put them all together in one query field like:

    =Left([Name], Instr([Name], ",")) & " " & Right([Name], 2) & " " & Mid([Name], Instr([Name], ", "), Instr([Name]," "))

    One caveat: parsing usually takes a bit of trial and error to get it just right. The code above will work partially, but you will have to tweak it to get the positioning just right - and as I said before, the original name field must be in the same order each time. If you have someone like "O'Brien, Michael Shawn" you could get issues...

  3. #3
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2007
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Using Stingaway's procedure, I would urge you to put the each porton of the name in separate fields. In this way, you can do sorts on the last name or if necessary only look up on certain last names. It just gives you more flexibility down the road should your requirements change.

    Alan

  4. #4
    Stingaway is offline Efficiency Junkie
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Location
    The deep south. Keep going until you hit water basically.
    Posts
    224
    Good point Alan. I usually have three fields and then a final field as well for the sort reason you listed...

  5. #5
    genemd is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    2
    Thanks for your help in solving my problem.

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

Similar Threads

  1. Can access take one text string and split it into two?
    By hobsondm01 in forum Database Design
    Replies: 2
    Last Post: 06-09-2011, 09:09 AM
  2. Breaking the string into Text / Number
    By Amerigo in forum Queries
    Replies: 15
    Last Post: 05-20-2011, 03:29 PM
  3. Replace a string/text in ms-access db
    By anziga in forum Queries
    Replies: 4
    Last Post: 12-31-2010, 06:40 PM
  4. Text string formatting
    By DanW in forum Forms
    Replies: 2
    Last Post: 11-02-2009, 11:11 AM
  5. Extract numbers from text string strored in a field.
    By khabdullah in forum Programming
    Replies: 2
    Last Post: 12-23-2007, 06:55 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