Listbox Order by not sequntial

B

Billy B

I have the following c ode in the OnLoad event of a form which generates the
numbers I need in an unbound control. The problem is the sequence order
being displayed (10, 11, 14, 159, 21, 211, 30). Is there any way I do to
correct the problem?

Me.lstCode.RowSource = "SELECT DISTINCT Code FROM [PO Master] WHERE Code <>
'""' ORDER BY Code ASC;"
 
K

Ken Snell

ACCESS is seeing your numbers as text, so it's sorting using text rules and
not number rules. Try this:

Me.lstCode.RowSource = "SELECT DISTINCT Code FROM [PO Master] WHERE Code <>
'""' ORDER BY Val(Code) ASC;"
 
B

Billy B

Thanks Ken. When I tried this but no results are showing in the listbox. I
copied your code and pasted it in the ON Load event but I'm not getting
anything.

Ken Snell said:
ACCESS is seeing your numbers as text, so it's sorting using text rules and
not number rules. Try this:

Me.lstCode.RowSource = "SELECT DISTINCT Code FROM [PO Master] WHERE Code <>
'""' ORDER BY Val(Code) ASC;"

--

Ken Snell
http://www.accessmvp.com/KDSnell/



Billy B said:
I have the following c ode in the OnLoad event of a form which generates
the
numbers I need in an unbound control. The problem is the sequence order
being displayed (10, 11, 14, 159, 21, 211, 30). Is there any way I do to
correct the problem?

Me.lstCode.RowSource = "SELECT DISTINCT Code FROM [PO Master] WHERE Code
<>
'""' ORDER BY Code ASC;"


.
 
K

Ken Snell

Probably a linewrapping problem? All I did was add the Val function as a
wrapper to your Code field in the ORDER BY clause. Go back to what you had
originally, then add the Val function as I did to your code.

--

Ken Snell
http://www.accessmvp.com/KDSnell/



Billy B said:
Thanks Ken. When I tried this but no results are showing in the listbox. I
copied your code and pasted it in the ON Load event but I'm not getting
anything.

Ken Snell said:
ACCESS is seeing your numbers as text, so it's sorting using text rules
and
not number rules. Try this:

Me.lstCode.RowSource = "SELECT DISTINCT Code FROM [PO Master] WHERE Code
<>
'""' ORDER BY Val(Code) ASC;"

--

Ken Snell
http://www.accessmvp.com/KDSnell/



Billy B said:
I have the following c ode in the OnLoad event of a form which generates
the
numbers I need in an unbound control. The problem is the sequence order
being displayed (10, 11, 14, 159, 21, 211, 30). Is there any way I do
to
correct the problem?

Me.lstCode.RowSource = "SELECT DISTINCT Code FROM [PO Master] WHERE
Code
<>
'""' ORDER BY Code ASC;"


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top