Hi, I have a description field in a table that contains both numbers and
text. I wrote a query with Like "*#*" in the criteria for that field so I
know that all rows returned have at least one number in that field.
Now I would like to return the first number in that field. For example, if
there is a row with AA1A2A, I would like to have 1 returned. If it is
A21AAA, I would like to have 2 returned.
Is this possible?
Thanks in advance for any help.
Jeff Boyce - 23 Oct 2006 21:16 GMT
I wonder if you might use Value([YourField]) to return the first numeric
value, then sort on that field?
Regards
Jeff Boyce
Microsoft Office/Access MVP
> Hi, I have a description field in a table that contains both numbers and
> text. I wrote a query with Like "*#*" in the criteria for that field so I
[quoted text clipped - 8 lines]
>
> Thanks in advance for any help.
Klatuu - 23 Oct 2006 21:36 GMT
Put the function below in a standard module.
Create a Calculated field in your query that calls the function passing the
field you want to check to the function. It will return the first character
in the field that is a number.
In the query:
TheNumber: FirstNumber([MyFieldName])
The function:
Public Function FirstNumber(strString As String) As Integer
Dim lngCtr As Long
Dim strTheChar As String
For lngCtr = 1 To Len(strString)
strTheChar = (Mid(strString, lngCtr, 1))
If IsNumeric(strTheChar) Then
FirstNumber = Cint(strTheChar)
Exit For
End If
Next lngCtr
End Function
> Hi, I have a description field in a table that contains both numbers and
> text. I wrote a query with Like "*#*" in the criteria for that field so I
[quoted text clipped - 7 lines]
>
> Thanks in advance for any help.
DB - 23 Oct 2006 22:35 GMT
Thanks! It worked great.
> Put the function below in a standard module.
> Create a Calculated field in your query that calls the function passing the
[quoted text clipped - 31 lines]
> >
> > Thanks in advance for any help.