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 » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Number Sorting Error



 
 
Thread Tools Display Modes
  #1  
Old October 30th, 2008, 01:15 PM posted to microsoft.public.access
Sam B.
external usenet poster
 
Posts: 5
Default Number Sorting Error

Hello all,

I'm having an issue with number sorting. I am trying to sort unit numbers
for my condo. When I run the query in ascending order the numbers are not
sorting correctly. Here is a small example of how the numbers are sorting:

1127
117
118
119
1201

Any help? It seems like Access is assuming the three digit numbers have a
zero on the end. In the table the field is set to "text". There are also PH1,
PH2, etc. in the list.

Thank you in advance,
Sam
  #2  
Old October 30th, 2008, 01:37 PM posted to microsoft.public.access
Allen Browne
external usenet poster
 
Posts: 11,706
Default Number Sorting Error

Open your table in design view.
Change the field data type from Text to Number.

For text fields, Access sorts character-by-character, so 1127 sort before
117 since the 3rd character (the 2) is less than the 3rd character of the
next string (the 7.) Use a Number field and it will sort numerically.

--
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.

"Sam B." wrote in message
...
Hello all,

I'm having an issue with number sorting. I am trying to sort unit numbers
for my condo. When I run the query in ascending order the numbers are not
sorting correctly. Here is a small example of how the numbers are sorting:

1127
117
118
119
1201

Any help? It seems like Access is assuming the three digit numbers have a
zero on the end. In the table the field is set to "text". There are also
PH1,
PH2, etc. in the list.

Thank you in advance,
Sam


  #3  
Old October 30th, 2008, 02:00 PM posted to microsoft.public.access
Sam
external usenet poster
 
Posts: 855
Default Number Sorting Error

Thank you Allen, I will try that. What happens though for the unit numbers
that start with PH (for penthouse)? They'll just sort at the end?

Sam

"Allen Browne" wrote:

Open your table in design view.
Change the field data type from Text to Number.

For text fields, Access sorts character-by-character, so 1127 sort before
117 since the 3rd character (the 2) is less than the 3rd character of the
next string (the 7.) Use a Number field and it will sort numerically.

--
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.

"Sam B." wrote in message
...
Hello all,

I'm having an issue with number sorting. I am trying to sort unit numbers
for my condo. When I run the query in ascending order the numbers are not
sorting correctly. Here is a small example of how the numbers are sorting:

1127
117
118
119
1201

Any help? It seems like Access is assuming the three digit numbers have a
zero on the end. In the table the field is set to "text". There are also
PH1,
PH2, etc. in the list.

Thank you in advance,
Sam



  #4  
Old October 30th, 2008, 02:15 PM posted to microsoft.public.access
Allen Browne
external usenet poster
 
Posts: 11,706
Default Number Sorting Error

You will not be able to put non-numeric characters in a Number field.

--
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.

"Sam" wrote in message
news
Thank you Allen, I will try that. What happens though for the unit numbers
that start with PH (for penthouse)? They'll just sort at the end?

Sam

"Allen Browne" wrote:

Open your table in design view.
Change the field data type from Text to Number.

For text fields, Access sorts character-by-character, so 1127 sort before
117 since the 3rd character (the 2) is less than the 3rd character of the
next string (the 7.) Use a Number field and it will sort numerically.

"Sam B." wrote in message
...
Hello all,

I'm having an issue with number sorting. I am trying to sort unit
numbers
for my condo. When I run the query in ascending order the numbers are
not
sorting correctly. Here is a small example of how the numbers are
sorting:

1127
117
118
119
1201

Any help? It seems like Access is assuming the three digit numbers have
a
zero on the end. In the table the field is set to "text". There are
also
PH1,
PH2, etc. in the list.


  #5  
Old October 30th, 2008, 02:59 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default Number Sorting Error

Try sorting using the Val function.
Val(NZ([Unit Numbers],""))

The above expression will sort numerically. Anything that starts with text
will be sorted as if it were zero. So you might want to add another sort on
[Unit Numbers] after the sort by the above expression.


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Allen Browne wrote:
You will not be able to put non-numeric characters in a Number field.

  #6  
Old October 30th, 2008, 03:11 PM posted to microsoft.public.access
KARL DEWEY
external usenet poster
 
Posts: 10,767
Default Number Sorting Error

For PH112 use this --
Val(Trim(NZ(Replace([Unit Numbers], "PH",""),""))))
--
KARL DEWEY
Build a little - Test a little


"John Spencer" wrote:

Try sorting using the Val function.
Val(NZ([Unit Numbers],""))

The above expression will sort numerically. Anything that starts with text
will be sorted as if it were zero. So you might want to add another sort on
[Unit Numbers] after the sort by the above expression.


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Allen Browne wrote:
You will not be able to put non-numeric characters in a Number field.


  #7  
Old November 3rd, 2008, 06:49 PM posted to microsoft.public.access
JimS
external usenet poster
 
Posts: 252
Default Number Sorting Error

I had exactly this question I posted in another section of this forum. I
tried your suggestion (which is simple and elegant...), but it doesn't seem
to be valid in the "order by" property of a form. I was able to construct a
query as the Control Source for the form that sorts using val(). My data has
####A, so I simply order by "val(ColumName),ColumnName "

Thanks
--
Jim


"KARL DEWEY" wrote:

For PH112 use this --
Val(Trim(NZ(Replace([Unit Numbers], "PH",""),""))))
--
KARL DEWEY
Build a little - Test a little


"John Spencer" wrote:

Try sorting using the Val function.
Val(NZ([Unit Numbers],""))

The above expression will sort numerically. Anything that starts with text
will be sorted as if it were zero. So you might want to add another sort on
[Unit Numbers] after the sort by the above expression.


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

Allen Browne wrote:
You will not be able to put non-numeric characters in a Number field.


  #8  
Old November 3rd, 2008, 08:05 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default Number Sorting Error

Val(Replace(Nz([Unit Numbers],""), "PH",""))


John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

JimS wrote:
I had exactly this question I posted in another section of this forum. I
tried your suggestion (which is simple and elegant...), but it doesn't seem
to be valid in the "order by" property of a form. I was able to construct a
query as the Control Source for the form that sorts using val(). My data has
####A, so I simply order by "val(ColumName),ColumnName "

Thanks

 




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 04:26 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.