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 / Forms / March 2007

Tip: Looking for answers? Try searching our database.

Sorting text field like a number field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Beth - 06 Mar 2007 23:40 GMT
I have a text field that stores numbers that may occassionally have letters
after them.  I need to be able to sort this field as if it is a number field
even though it holds text.  Unfortunately, that is not something I have an
option to change, but I have to find a way to work with it.
The problem comes with the numbers 1-9 falling in the wrong place with the
text sort.
Does anyone have a suggestion on how to correct that in the sorting?  The
only thing I came up with was very messy.  That was to use nested if
statements to handle 1-9.

I am open to suggestions.

Thanks,
Beth
Allen Browne - 07 Mar 2007 00:09 GMT
Type this expression into the Field row in query design:
   Val(Nz([Field1],"0"))

Choose Ascending in the Sorting row under this field.

Val() ignores trailing non-numeric charactrers.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

>I have a text field that stores numbers that may occassionally have letters
>after them.  I need to be able to sort this field as if it is a number
[quoted text clipped - 10 lines]
> Thanks,
> Beth
fredg - 07 Mar 2007 00:21 GMT
> I have a text field that stores numbers that may occassionally have letters
> after them.  I need to be able to sort this field as if it is a number field
[quoted text clipped - 10 lines]
> Thanks,
> Beth

If the data is like:
8123PLU
23XZ
765KJM

Create a query that will be used as the form's record source.
Add a new column.

SortThis:Val([Fieldname])

Sort by this field.
Signature

Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

 
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.