A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Setting Up & Running Reports
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Sorting by Text field of numbers



 
 
Thread Tools Display Modes
  #1  
Old January 20th, 2010, 05:14 PM posted to microsoft.public.access.reports
Aurora
external usenet poster
 
Posts: 224
Default Sorting by Text field of numbers

I am using Access 2003.
I have created a database to help me files by "Lot#'s". Our lot numbers for
one of our products is all over the place so I created the Lot # field as a
text field. Ex: 02-01-01, 10000272925, 10-06-02-04-06 and 1503011 A1-02.
Why does access put - 1000272925 before 10-06-02-03-05? Does this look right
to anyone?

My thinking is that "10" comes before "1000272925". What affect does the
"-" have in sorting the numbers. Would I be better off to put a space
instead of the "-"? Can anyone help me with this problem?

Aurora
  #2  
Old January 20th, 2010, 05:30 PM posted to microsoft.public.access.reports
Stefan Hoffmann
external usenet poster
 
Posts: 991
Default Sorting by Text field of numbers

On 20.01.2010 18:14, Aurora wrote:
I am using Access 2003.
I have created a database to help me files by "Lot#'s". Our lot numbers for
one of our products is all over the place so I created the Lot # field as a
text field. Ex: 02-01-01, 10000272925, 10-06-02-04-06 and 1503011 A1-02.
Why does access put - 1000272925 before 10-06-02-03-05? Does this look right
to anyone?

Yes, because the hyphen is in the ASCII order after the numbers.

You may try using Replace() in your order criteria:

ORDER BY Replace([Lot#'s], "-", "")

You may need some left padding also, e.g.

ORDER BY
Right("0000000000000000" & Trim(Replace([Lot#'s], "-", "")), 16)


mfG
-- stefan --
  #3  
Old January 20th, 2010, 06:09 PM posted to microsoft.public.access.reports
Marshall Barton
external usenet poster
 
Posts: 5,361
Default Sorting by Text field of numbers

Aurora wrote:

I am using Access 2003.
I have created a database to help me files by "Lot#'s". Our lot numbers for
one of our products is all over the place so I created the Lot # field as a
text field. Ex: 02-01-01, 10000272925, 10-06-02-04-06 and 1503011 A1-02.
Why does access put - 1000272925 before 10-06-02-03-05? Does this look right
to anyone?

My thinking is that "10" comes before "1000272925". What affect does the
"-" have in sorting the numbers. Would I be better off to put a space
instead of the "-"? Can anyone help me with this problem?



Those are NOT numbers, they are text strings that are being
sorted in the usual dictionary order. If you want them
sorted as if they were numbers, you will have to convert
them to actual numbers by removing the non digits and using
a conversion function (Val, CLng, ?) to get actual numbers
for sorting.

--
Marsh
MVP [MS Access]
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:23 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.