Results 1 to 4 of 4
  1. #1
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97

    Query correctly extracts away middle, but wrongly extracts last name if not middle

    Hey all,

    There's a problem with this query:

    Code:
    SELECT p.an INTO GeneralWithout
    FROM (SELECT Left([name],IIf(InStrRev([name]," ")>1, InStrRev([name]," ")-1,Len([name]))) AS an FROM Forgotten)  AS p;

    Basically I am trying to extract away a middle initial (or middle name) if it exists. It correctly extracts away middle initial in this scenerio:

    Dougal Anthony John

    outputing this:

    Dougal Anthony

    However, if the name has no middle initial:

    Alvarado Michael

    then it outputs this incorrectly:

    Alvarado

    whereas I wanted it to remain as is since no middle initial existed:

    Alvarado Michael





    Thanks for response
    Last edited by johnmerlino; 05-08-2011 at 01:30 PM.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    John,

    I just wanted to say something here. This is like the 10th thread you've started about this same issue. And if I remember right, I've helped you with a lot of it. Have you considered using a utility to do this stuff? I would feel REALLY bad if you have been working on this since 5 or so months ago when we initially talked about this complexity.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2007
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Yeah, this looks like a lost cause. Doubt could ever get code that could handle every possible name configuration. With the examples you show, only thing I could suggest is that you check the string for multiple spaces. If there is more than one then likely a middle name is present then proceed with extract and keep parsing until only one space is present. This would probably work for: Carson Mary Beth Anne; but what about Van Der Beek James Carl?

  4. #4
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    Quote Originally Posted by June7 View Post
    but what about Van Der Beek James Carl?
    Sure there will be exceptions. But I can't say I know many Van Der Beek James Carl's.

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

Similar Threads

  1. Inserting a New Field in Middle of Table
    By AccessGeek in forum Programming
    Replies: 4
    Last Post: 03-14-2011, 09:22 AM
  2. More than one middle name
    By vorstopzolder in forum Access
    Replies: 5
    Last Post: 02-10-2011, 01:09 AM
  3. Changing color in middle of email message
    By tgavin in forum Programming
    Replies: 5
    Last Post: 11-30-2010, 01:19 PM
  4. how select middle characters on string ???
    By ayman.maher in forum Queries
    Replies: 1
    Last Post: 04-27-2010, 09:29 AM
  5. Extract text from middle of a field
    By AccessNubie in forum Access
    Replies: 3
    Last Post: 11-02-2009, 01:13 PM

Tags for this Thread

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