Query Expression

kitty77

Registered User.
Local time
Today, 11:18
Joined
May 27, 2019
Messages
715
How can I create an expression in a query that brings back only after the last \?
Also, if the field has no value then return a blank or null.

\6002.pdf (should look like this)
\\SERVER\Plus\Spec\Results\ABC\ABC\Results\6002.pdf

Thanks.
 
Check out the InStrRev() function. That along with the Mid() function should get what you want. You'll have to first test for blank/null/no slash.
 
Any examples you could provide?
 
Not offhand, just start with the InStrRev() and work your way out a step at a time. Post back if you get stuck.
 
It can be done with just the mid and instrrev, but you likely in a query will have to handle a Null value and a value without a slash
You can do it in line with an iif but easier to do a simple UDF.
Code:
Public Function AfterSlash(TheVal As Variant) As Variant
  AfterSlash = TheVal
  If Not IsNull(TheVal) Then
    If InStr(AfterSlash, "\") > 0 Then
      AfterSlash = Mid(AfterSlash, InStrRev(AfterSlash, "\") + 1)
    End If
  End If
End Function

Or the painful inline
Code:
IIf(InStr([field1],"\")>0,Mid([field1],InStrRev([field1],"\")+1),[field1])
 
Last edited:
See
which is almost the exact opposite question. The OP wanted to remove everything after the last slash.
 
It can be done with just the mid and instrrev, but you likely in a query will have to handle a Null value and a value without a slash
You can do it in line with an iif but easier to do a simple UDF.
Code:
Public Function AfterSlash(TheVal As Variant) As Variant
  AfterSlash = TheVal
  If Not IsNull(TheVal) Then
    If InStr(AfterSlash, "\") > 0 Then
      AfterSlash = Mid(AfterSlash, InStrRev(AfterSlash, "\") + 1)
    End If
  End If
End Function

Or the painful inline
Code:
IIf(InStr([field1],"\")>0,Mid([field1],InStrRev([field1],"\")+1),[field1])
Perfect!
 

Users who are viewing this thread

Back
Top Bottom