Results 1 to 5 of 5
  1. #1
    jaykappy is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2009
    Posts
    59

    Get trailing Characters from String

    I have the strings below...I want the values to the right of the second _
    Note there will be different numbers of characters so a simple Right([field] , 3) wont work



    A3_B4_C1
    A3_B4_C12
    A3_B4_C122

    Thoughts....some sort of Mid? Not sure of the syntax

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I use instrrev for situations like this. A string contains multiple instances of a special character and I want the text after the last instance. Here is an example.

    Code:
    Dim strInternational As String
    Dim strYear As String
    
    'assign user input to string variable
    strInternational = "28-2-2010 1:20:59 PM"
    
    strYear = Mid(strInternational, InStrRev(strInternational, "-") + 1)
    Debug.Print "strYear = " & strYear

  3. #3
    jaykappy is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2009
    Posts
    59
    If I am doing this from a Query Builder would the below work...

    I assume I can replace the - with the _ that is needed?



    Mid(FieldName, InStrRev(FieldName, "-") + 1)

    or

    Mid( [FieldName], InStrRev( [FieldName], "-") + 1)

  4. #4
    jaykappy is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2009
    Posts
    59
    YES this worked Perfectly...

    Mid( [A_B_C] , InStrRev( [A_B_C] , "_") + 1)

    THANK YOU MUCH

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Did not notice I was in the Queries forum. Glad you got it sorted.

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

Similar Threads

  1. Omitting characters from a string
    By TonyB in forum Queries
    Replies: 4
    Last Post: 04-07-2014, 08:03 AM
  2. Replies: 6
    Last Post: 10-18-2013, 07:30 AM
  3. Characters before searched string
    By cleme1q in forum Access
    Replies: 4
    Last Post: 12-10-2011, 11:22 AM
  4. Replies: 4
    Last Post: 12-02-2011, 11:20 AM
  5. replace characters in a string
    By blazixinfo@yahoo.com in forum Access
    Replies: 6
    Last Post: 08-06-2009, 03:36 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