Results 1 to 8 of 8
  1. #1
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283

    Remove Characters before a certain part of a string

    Hello,

    I have made it so my database inputs the name of the file that was imported into my table(PVE) and it goes into the field, FileName. The end of the string is what I want to save, the rest I want to remove. this is an example of the string: dhaskdnhasklds//sdasdas/PROD_MAD_0e3433.txt I want to remove everything before *PROD*. And the length of characters before PROD will change everytime. And the number of characters I want to keep after PROD, including PROD is 33. I was asking if anyone can help me solve removing those characters with the length changing everytime..except the PROD will always be there..thank you

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    I count only 15 characters following PROD.

    x represents the value.

    Mid(x, InStr(x, "PROD")+4)
    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.

  3. #3
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    I was just giving an example of what I was trying to say. I didn't want to give an actual file path. But there are 33 characters including PROD that I want to keep in the file path. and that is everything at the end after PROD. and the number of characters before PROD will change. so won't "x" need to change all the time?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    My example doesn't care how many characters precede or follow "PROD", just that PROD is always there.

    X is just a variable to represent value in the formula. You could do this calc in a query and reference fieldname in place of x.
    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
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    Oh okay sorry I never did this before, didn't realize x was supposed to be the Field Name. Okay I got it to work. But PROD is just missing from it. I want to include PROD in the output

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    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
    MTSPEER is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    283
    Thank you very much! It works!

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Here are three other examples that might help you understand how to use InStrRev() and Right() functions.

    As Subs
    Code:
    Sub extraction1()
        'multi step
        Dim s As String
        Dim FN As String  'file name
        Dim pos As Integer
        Dim FN_Len As Integer
    
        FN = "dhaskdnhasklds//sdasdas/PROD_MAD_0e3433.txt"
    
        FN_Len = Len(FN)
        pos = InStrRev(FN, "/")
    
        s = Right(FN, FN_Len - pos)
        Msgbox "Filename is " & s
    
    End Sub
    
    Sub extraction2()
        'one line
        Dim s As String
        Dim FN As String  'file name
    
        FN = "dhaskdnhasklds//sdasdas/PROD_MAD_0e3433.txt"
    
        s = Right(FN, Len(FN) - InStrRev(FN, "/"))
        Msgbox "Filename is " & s
    
    End Sub
    As a function
    Code:
    Function extraction3(pFileName As String) As String
        'one line
        Dim FN As String
    
        FN = Right(pFileName, Len(pFileName) - InStrRev(pFileName, "/"))
    
        'return value
        extraction3 = FN
    
    End Function

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

Similar Threads

  1. Replies: 3
    Last Post: 07-28-2014, 06:03 PM
  2. Remove Only Part of Record Using Unmatched Query
    By garrettgivre in forum Access
    Replies: 8
    Last Post: 08-13-2013, 03:15 PM
  3. Replies: 12
    Last Post: 03-03-2013, 07:13 PM
  4. Replies: 5
    Last Post: 06-28-2012, 10:49 AM
  5. Replies: 5
    Last Post: 03-10-2011, 02:19 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