Results 1 to 2 of 2
  1. #1
    DBS is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2012
    Posts
    3

    Query to extract different values from variable string ?

    I use the following string to capture/record notes in a field:

    String: AA-AnyTwoLettersHere(ddShortMonthYYYY)
    Example: AA-BB(05May2012)

    I want to extract
    a) the two letters following "AA-"
    b) the date in brackets.

    Problem is the field may also contain similar variations of the string, such as:

    AA-BB(05May2012_SomeTextHere) - Don't want to extract the text following the date

    AA-BB/05May2012 - Don't want to extract anything here because it follows a different convention

    To make it more complicated, if the string is found more than once in the field I want to only extract the two bits of info from the LAST instance of it in the field.



    Does anyone think they can help me?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Well, I'll get it started, though it looks like it could get messy. The 2 letters are easy, you can use the Mid() function. You can also use the Mid() function along with the InStr() function to find the "(". Since the "(" may or may not be there, probably an IIf() to only pull the value if it is.

    If you're saying the whole bit can repeat in the field, it get's messier. If the data supports it, You can use InStrRev() to find the last occurrence of either the "-" or "(" and pull from there. If the text in the "SomeTextHere" area could contain either of those, all bets are off.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Extract Value from Variable in String
    By nguyenak in forum Programming
    Replies: 3
    Last Post: 05-24-2012, 03:50 PM
  2. Extract String From Between 2 Values
    By kathleencampbell in forum Queries
    Replies: 5
    Last Post: 03-23-2012, 10:52 AM
  3. Extract certain values from field
    By tylerg11 in forum Programming
    Replies: 19
    Last Post: 09-23-2011, 03:27 PM
  4. Convert Number to String in .csv extract
    By CindyR19 in forum Import/Export Data
    Replies: 3
    Last Post: 08-17-2011, 02:58 PM
  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