MS Access: Find position of first occurrence of number in a string

I needed to retain string before first occurrence of number with in it.
With the below function I could get position of first occured number.
Public Function PosOfFirstDigit(strTest As String) As Long

Dim i As Long

PosOfFirstDigit = 0
For i = 1 To Len(strTest)
If Mid$(strTest, i, 1) Like "#" Then
PosOfFirstDigit = i
Exit For
End If
Next

End Function


With the help of above function I could use the below query to obtain string available before first occurred number.
FirstNumberPosition: Left([Desc],PosOfFirstDigit([DESC])-1)

No comments:

Post a Comment