Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2010
    Location
    Atlanta, GA
    Posts
    213
    Provided Answers: 2

    Question Unanswered: Extracting characters in a string based on multiple "-" placement

    I have semi-standardized strings in the form of [alphanum1]-[alphanum2]-[alphanum3]. I need to strip out each section into it's own field. to get [alphanum1], i used this code:

    Code:
     FirstPart: Mid([fieldname],1,InStr([fieldname],'-')-1)
    But i am struggling how to pull the 2nd and 3rd part. Any suggestions?

    EDIT: Extracted the 2nd part with this code:
    Code:
    SecondPart:Mid([fieldname],Len([FirstPart])+2,InStr(Len([FirstPart])+2,[fieldname],'-')-InStr([fieldname],'-')-1)
    there has to be an easier way!
    Last edited by clawlan; 04-08-11 at 14:57.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    See if the Split() function helps you out.
    Paul

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,764
    Provided Answers: 19
    Per Paul's suggestion
    Code:
    Components = Split(Me.YourCompleteField, "-", -1)
    
    Part1 = Components(0)
    Part2 = Components(1)
    Part3 = Components(2)
    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 15
    First and third parts are easy:
    Code:
    Left(FieldName, InStr(FieldName, "-") - 1)
    and:
    Code:
    Mid(FieldName, InStrRev(FieldName, "-") + 1)
    The second (middle) part is trickier:
    Code:
    Mid(FieldName, (InStr(FieldName, "-") + 1), (InStrRev(FieldName, "-") - (InStr(FieldName, "-") + 1)))
    Have a nice day!

  5. #5
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,482
    Provided Answers: 11
    use the split function
    hope this help

    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.
    DONT WORRY ABOUT THOSE WHO TALK BEHIND YOUR BACK
    THEY'RE BEHIND YOU FOR A REASON

  6. #6
    Join Date
    Oct 2010
    Location
    Atlanta, GA
    Posts
    213
    Provided Answers: 2
    Quote Originally Posted by myle View Post
    use the split function
    Split doesn't work in the query editor; must only be able to use in VBA, which I am trying to avoid.

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,764
    Provided Answers: 19
    Quote Originally Posted by clawlan View Post
    Split doesn't work in the query editor; must only be able to use in VBA, which I am trying to avoid.
    It would have been nice if your original post mentioned this fact!

    So use Sinndho's code to create calculated fields in the Query Editor.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •