Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    cliff.clayman is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    55

    How can I build an expression to extract text in two different formats?


    I have a Name field in an Access table with different formats. Sometimes the name is formatted like Smith, John and sometimes it is John Smith. I am trying to pull the last name into a separate field. I created this to pull for the format with the comma, but how can I add an additional way to pull the last name when there is no comma?

    LName: Left([FullName],InStr(1,[FullName],",")-1)

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    Name parts should be in separate fields.

    LName: IIf(InStr([FullName], ",")>0, Left([FullName],InStr(1,[FullName],",")-1), Mid([FullName],InStr(1,[FullName]," ")+1))

    However, this assumes names are not like: Mary Jane Carter.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    cliff.clayman is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    55
    I do have some values that are like Mary Jane Carter. How can I extract that?

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Look at your data in very broad terms. Do you see any patterns?
    I think you are sayiing

    -LastName, FirstName
    -FirstName Lastname
    -FirstName MiddleName LastName

    My experience says you may also see something like

    Angela D'Orsini.....+Names containing single quote character
    Paddy O'Malley.....+ Names containing single quote character
    Ali van't Goor........+multipart lastname strange capitalization with embedded single quote
    Oscar de la Hoya....+multipart lastname strange capitalization

    Look for patterns. Solve each pattern.

    Read a record
    determine the pattern
    call the Pattern Solver.

    Good luck.

  5. #5
    cliff.clayman is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    55
    Ok, I adjusted me search name field, but now my match expression is not working.

    Here is the code for the field that pulls out either the last name or the full name:

    SearchName: IIf(InStr([Name],",")>0,Left([Name],InStr(1,[Name],",")-1),[Name])

    Here is the code to see if the SearchName exists in the Name field:

    Expr1: InStr(IIf(IsNull([Insured Name]),"N/A",[Insured Name]),Left([Name],InStr(1,[Name],",")-1))=0

    It fails when the SeachName is the same value as the Name. How can I adjust the Expr1 code to work?

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    How can that work at all? If [Name] has a varied structure as indicated by the SearchName expression, would have to do the same parsing of [Name] in Expr1. And if SearchName has only a last name extracted, how can the [Insured Name] be matched?

    This is why name parts should be in separate fields. It is easier to concatenate strings than split them.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    cliff,

    Please post a sample of your data (10-20 records).

  8. #8
    cliff.clayman is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    55
    Adams, Robert
    ACS
    Anderson, Jr,Chris
    Jenkins, La'Roy
    Ashner-Trujillo, Kelly
    Arredondo Arevalo, Ezekial
    Austin-Green, Esq., Alex
    Az State Board
    Bankers' Multiple Line Ins Co
    Boop, Elizabeth "Betty"
    Estate Of Arlene Patel
    Johnson, III, Donald


    These are about all the varieties that I could find. My current code seems to work for everything except for the names that do not have a comma in them. How can I add an exception to the code to just return the entire name field if there is no comma?


    ChkName: InStr(IIf(IsNull([Client Name]),"N/A",[Client Name]),Left([Client_Name],InStr(1,[Client_Name],",")-1))=0


    In my condition, I look for -1

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    Test for the presence of comma first. See post 2.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Cliff,

    I am attaching a database that uses your sample data.
    I have it set with vba routines to output :
    ---FName LName (suffix if applicable)
    or--if it isn't a person, I simply output the original

    You can go to the module, and run cliffnames.
    The output is:
    Robert Adams
    ACS
    Chris Anderson Jr
    La'Roy Jenkins
    Kelly Ashner-Trujillo
    Ezekial Arredondo Arevalo
    Alex Austin-Green Esq.
    Az State Board
    Bankers' Multiple Line Ins Co
    Elizabeth "Betty" Boop
    Estate Of Arlene Patel
    Donald Johnson III


    Good luck.
    Attached Files Attached Files
    Last edited by orange; 12-03-2015 at 07:50 PM. Reason: spelling

  11. #11
    cliff.clayman is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    55
    Nothing happens when I run the module...

  12. #12
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    Cliff,
    Did you look in the immediate window?
    I just downloaded the database and ran the module, it put the extracted output in the immediate window.

  13. #13
    cliff.clayman is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    55
    No, I did not look there. I see it now. How can I apply this to my query?

  14. #14
    cliff.clayman is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2015
    Posts
    55
    Okay, I think I determined how to apply this to a query, but I am having a couple of issues. How do I handle NULL values in a name field?

  15. #15
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,964
    One way from query:

    SplitName(Nz([fieldname],""))

    or

    SplitName(IIf([fieldname] Is Null, "", [fieldname]))

    Review http://allenbrowne.com/QueryPerfIssue.html


    The does assume that organizations do not use comma in name - that does appear to be the norm but is it possible to find comma in organization name?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Build Expression in Query
    By rwpspackett in forum Queries
    Replies: 1
    Last Post: 11-23-2015, 02:16 PM
  2. Replies: 4
    Last Post: 05-26-2015, 12:21 PM
  3. Replies: 3
    Last Post: 08-18-2014, 10:11 AM
  4. Replies: 1
    Last Post: 03-13-2014, 03:02 PM
  5. Issues with Text Box formats and expressions
    By AndrewsPanda in forum Reports
    Replies: 3
    Last Post: 09-28-2011, 11:32 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