Function fGetNumber(ByVal Str As String) As Long
Dim RE As Object, Match As Object, Matches As Object
Set RE = CreateObject("VBScript.RegExp")
With RE
.Global = False
.Pattern = "(\d+)(\\)?$"
End With
If RE.test(Str) Then
Set Matches = RE.Execute(Str)
fGetNumber = Matches(0).submatches(0)
End If
End Function
REgards
GetNumber = Matches(0).Submatches(0)
Option Compare Database
Option Explicit
Public Function GetNumber(ByVal Str As String) As Long
Dim RE As Object, Match As Object, Matches As Object
Set RE = CreateObject("VBScript.RegExp")
With RE
.Global = False
.Pattern = "\\(\d+)\\"
End With
If RE.test(Str) Then
Set Matches = RE.Execute(Str)
GetNumber = Matches(0)
End If
End Function
Option Compare Database
Option Explicit
Function fGetNumber3(ByVal Str As String) As Long
Dim strParts() As String
strParts = Split(Str, "\")
fGetNumber3 = strParts(UBound(strParts) - 1)
Debug.Print
End Function
Option Compare Database
Option Explicit
Public Function GetNumber(ByVal Str As String) As Long
Dim RE As Object, Match As Object, Matches As Object
Set RE = CreateObject("VBScript.RegExp")
With RE
.Global = False
.Pattern = "\\(\d+)\\"
End With
If RE.test(Str) Then
Set Matches = RE.Execute(Str)
GetNumber = Matches(0).Submatches(0)
End If
End Function
Public Function GetNumber(ByVal AValue As Variant) As Long
I am not sure how to do the msg box... nowhere in the code does it contain [FPath]... just in the query grid. Sorry, I am not experienced with this..And since I don't know Access very well I'm just confusing things, so I'll drop out of the conversation.
Option Compare Database
Option Explicit
Public Function fGetNumber3(ByVal AValue As Variant) As Variant
On Local Error GoTo LocalError
fGetNumber3 = Null
'Function body.
Exit Function
LocalError:
fGetNumber3 = Null
Debug.Print "Error: " & Err.Number & " - " & Err.Description
On Local Error Resume Next
Debug.Print "For Value: [" & CStr(AValue) & "]"
End Function
Option Compare Database
Option Explicit
Public Function fGetNumber3(ByVal AValue As Variant) As Variant
' Return found Number or NULL
' Using Martin Liss's get last path part approach.
On Local Error GoTo LocalError
Dim Path() As String
fGetNumber3 = Null
If Len(Trim(AValue & "")) > 0 Then
Path() = Split(CStr(AValue), "\")
fGetNumber3 = Path(UBound(Path()) - 1)
End If
Exit Function
LocalError:
fGetNumber3 = Null
Debug.Print "Error: " & Err.Number & " - " & Err.Description
On Local Error Resume Next
Debug.Print "For Value: [" & CStr(AValue) & "]"
End Function
Option Compare Database
Option Explicit
Public Function fGetNumber3(ByVal AValue As Variant) As Variant
' Return found Number or NULL
' Using Martin Liss's get last path approach.
On Local Error GoTo LocalError
Dim Path() As String
fGetNumber3 = Null
If Len(Trim(AValue & "")) > 0 Then
Path() = Split(CStr(AValue), "\")
fGetNumber3 = Path(UBound(Path()) - 1)
If Not IsNumeric(fGetNumber3) Then
fGetNumber3 = Null
End If
End If
Exit Function
LocalError:
fGetNumber3 = Null
Debug.Print "Error: " & Err.Number & " - " & Err.Description
On Local Error Resume Next
Debug.Print "For Value: [" & CStr(AValue) & "]"
End Function
any number from 1 to 99999is not a precise definition.
Open in new window
And then try this as...Open in new window