Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / October 2006

Tip: Looking for answers? Try searching our database.

Find First Number

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DB - 23 Oct 2006 21:00 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.