JohnLute said:
Thanks, Dirk!
I can't exactly recall about the spaces. The fields contain alpha and
numeric values and I believe I had to use the spaces in order to make
it work. The right-most 4 characters assured that I was getting the
proper numeric sequence:
All
Even
20
10
3
2
1
Instead of
1
10
2
20
3
All
Even
Ah, I see.
Is there an easier/more proper way?
Probably not without changing your table structure. You've got a text
field that you want to sort into numeric sequence, but with exceptions
for certain non-numeric data. That presents a natural problem.
Depending on the nature of the exceptions, you might have used a number
field instead of the text field, but with certain special values to
represent the exceptions; for example, -1 and -2 to represent "All" and
"Even", or 99999 and 99998 (to simplify descending sorts). Of course, a
solution like that requires translation of the field value to the
appropriate text before you display it to the user on a form or report.
Other alternatives would include breaking the field into two fields, one
of which indicates "All", "Even", or "Number", and the other of which (a
numeric field) would contain the numeric value when the first field is
"Number". Or you could use a single text field, but always pad out the
numeric values with leading zeros, so they sort properly -- but here
you're at the mercy of the controls you put on data entry.
In general, your queries will run more efficiently if they don't have to
call a VBA function to convert the field before sorting by it. Whether
efficiency is a problem in this database, with this query, is another
question entirely. No need to waste a lot of time seeking efficiency if
everything is running fine.
This is mt SQL but I;m not sure where to plug in the ORDER BY clause
- my brain has cramped suddenly:
SELECT tblFGUnitLoadsLayerParameters.txtProfileID,
tblFGUnitLoadsLayerParameters.Layer,
tblFGUnitLoadsLayerParameters.LayerParameters,
tblFGUnitLoadsLayerParameters.Sequence,
tblFGUnitLoadsLayerParameters.Quantity,
tblFGUnitLoadsLayerParameters.Comments FROM
tblFGUnitLoadsLayerParameters;
SELECT
txtProfileID,
Layer,
LayerParameters,
Sequence,
Quantity,
Comments
FROM
tblFGUnitLoadsLayerParameters
ORDER BY
Right(" " & [Layer], 4) DESC,
Right(" " & [Sequence], 4) DESC;
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)