Results 1 to 7 of 7
  1. #1
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96

    expression to capture varying length of numbers between brackets

    I'm trying to figure out how to capture a number that appears between [ ] in a varying length field. I'm currently using:

    Financial Class code: Mid([tbltemp_PB_import]![payor financial class],InStr([tbltemp_PB_import]![payor financial class],"[")+1,4) , which is giving me everything after [. Instead of going over 4 characters though, I want to stop at ], so I only display the number within. The field I'm trying to capture this number from is varying length, as well as the number within the [ ] can be a varying length. Here is a sample of the data I'm trying to break up. Any ideas?
    Payor Financial Class
    Nebraska Medicaid [104]
    Medicare [2]
    MEDICARE ADVANTAGE [101]
    Nebraska Medicaid [104]
    Medicare [2]
    Blue Cross Blue Shield [100]


  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
    If it's always at the end:

    ?Val("123]")
    123
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Try,

    Financial Class code: Mid([tbltemp_PB_import]![payor financial class],InStr([tbltemp_PB_import]![payor financial class],"[")+1, InStr([tbltemp_PB_import]![payor financial class], "]") - InStr([tbltemp_PB_import]![payor financial class], "[") - 1)

  4. #4
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    ifpm062010's answer is what I had pictured in my head, but both solutions appeared to achieve the same result, so thank you to both. I will mark this thread as solved, but can I ask a theory question based on these two solutions? Are there any implications of using one of the solutions versus the other? Thinking down the road, will this new field be formatted the same either way? When I tried both solutions, I noticed that pbaldy's solution pushed the numbers to the right side of the field, whereas ifpm062010's solution left the numbers on the left. Maybe it doesn't matter, I just want to understand the function behind the expression, so I can use it properly down the road. Thanks again!!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    From help, the Val() function "stops reading the string at the first character it can't recognize as part of a number" Since your existing function would return a value that starts with a number, the Val() function is a shortcut that will trim off the non-numeric portion and as you saw, returns a numeric value. The other function is longer but should return the same numbers. As you also saw, because the field it started with was text, it returned a text value. That could be overcome by adding a conversion function like CInt(). As is often the case, more than one way to skin a cat.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Paintballlovr is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Jul 2013
    Posts
    96
    Quote Originally Posted by pbaldy View Post
    From help, the Val() function "stops reading the string at the first character it can't recognize as part of a number" Since your existing function would return a value that starts with a number, the Val() function is a shortcut that will trim off the non-numeric portion and as you saw, returns a numeric value. The other function is longer but should return the same numbers. As you also saw, because the field it started with was text, it returned a text value. That could be overcome by adding a conversion function like CInt(). As is often the case, more than one way to skin a cat.
    Thank you very much for the detailed explanation!

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    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. Report with varying row heights
    By AKWells in forum Reports
    Replies: 7
    Last Post: 04-24-2014, 10:48 AM
  2. Replies: 4
    Last Post: 11-19-2013, 06:53 PM
  3. Replies: 1
    Last Post: 07-12-2013, 01:15 PM
  4. Search for brackets
    By stocktsi in forum Access
    Replies: 3
    Last Post: 11-14-2011, 06:18 PM
  5. Get Varying Query Columns into Report
    By Elios in forum Reports
    Replies: 1
    Last Post: 05-05-2011, 03:16 AM

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