Results 1 to 7 of 7
  1. #1
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97

    extracting data from field

    I have a field in a table containing data like these :



    "A21(1500),B27(500),C18(1000),DP15(2000)"
    "A32(2000),B27(1000),C19(2000),DR20(1000)"

    I also have a query by form that finds all records containing, e.g., "B27" by setting the criterion to :

    Like "*" & [Forms]![Form_name]![Search_field_name] & "*"

    Is there any way to output in a query column the value between parentheses (i.e., for B27 :
    500
    1000

    ??
    I guess I have to use a combination of InstrRev and Right functions, but can't find the right way to combine them...

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    I just tried this in a new field in a query:
    InParens: Mid([REASON],InStr([REASON],"(")+1,(InStr([REASON],")")-1)-InStr([REASON],"("))

    The field 'InParens' extracts what is within the parens in the REASON field.

    See screenshot for what my data looks like.

    Hope this helps!!

  3. #3
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Quote Originally Posted by Robeen View Post
    I just tried this in a new field in a query:
    InParens: Mid([REASON],InStr([REASON],"(")+1,(InStr([REASON],")")-1)-InStr([REASON],"("))

    The field 'InParens' extracts what is within the parens in the REASON field.

    See screenshot for what my data looks like.

    Hope this helps!!
    Thanks a ton Robeen. You helped me a lot. "Mid" and "InStr" functions were good hints. Actually my task is a little more complicated since :
    1) I'm using query by form
    2) my field contains multiple round parentheses.

    Anyway :

    1) I replaced "(" in your syntax with [Forms]![Form_name]![search_field_name" and the start_position in the Mid function is correctly found
    2) in the number_of_characters part of the Mid function, I can make the same replacement for "(", but I still can't understand how to represent the next ")" in the field... (as you can see I have multiple pairs of parentheses in each field, and the number of characters between each pair of parentheses varies from 3 to 5)

    Any hint to fix this last part ?
    Thanks again

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Do you need to parse all the values from each pair of parens or only for B27?
    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.

  5. #5
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Quote Originally Posted by June7 View Post
    Do you need to parse all the values from each pair of parens or only for B27?
    Only for the parameter inputted in the query by form (B27 in my example). And each parameter occurs only once in the string.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,919
    Try:

    x = "A32(2000),B27(1000),C19(2000),DR20(1000)"
    y = "C19"
    Val(Mid(x,Instr(x,y)+Len(y)+1))

    I use x and y for convenience. You will of course reference your field and form input.
    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
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Quote Originally Posted by June7 View Post
    Try:

    x = "A32(2000),B27(1000),C19(2000),DR20(1000)"
    y = "C19"
    Val(Mid(x,Instr(x,y)+Len(y)+1))

    I use x and y for convenience. You will of course reference your field and form input.
    Wow, I was not aware of the "Val" function ! Works like a charm. Thanks a ton.

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

Similar Threads

  1. Help! Extracting Data from table to Form.
    By iProRyan in forum Forms
    Replies: 3
    Last Post: 01-29-2012, 02:12 PM
  2. Replies: 3
    Last Post: 03-05-2011, 12:46 PM
  3. Extracting text from a field
    By bwash70 in forum Access
    Replies: 4
    Last Post: 11-24-2010, 08:10 PM
  4. Extracting text from XML data
    By rob4465 in forum Access
    Replies: 1
    Last Post: 03-18-2010, 06:41 PM
  5. Extracting data after a keyword
    By KerryA in forum Queries
    Replies: 1
    Last Post: 02-11-2010, 09:56 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