If I set the sort order in the query, then it opens fine.
The light bulb just went off! I was creating a sort in the report, but just
confusing it with grouping since I don't create a header or footer, etc.
Yes, if I create a sort for the LotNumberSort first and then the
LotSortAlpha, it works fine. I kept thinking I had to sort it another way
instead of using the Sorting and Grouping window, but since all I am doing
is sorting this works. I also wasn't creating both sorts, just the alpha
thinking the query did the actual sorting, but since I am not using those
fields, I have to create the sort in the report to get it in the proper
order. Am I right now?
Sorry I am making this so hard! Thanks!
tina said:
I do not use the field values created in the query within the report
(or should I?)
if you mean you don't use those calculcated query fields to display data in
the report, then no, that shouldn't make a difference to the
sorting/grouping.
Also, does this need to be an expression or just Group By?
you lost me entirely on that one.
let's back up a step. you already created the two calculated fields in your
query. set a sort on those two fields in the query, then open the query in
datasheet view. does it sort as intended?
if so, close the query without saving the Sort changes. go back to your
report, and make sure that you've set the Sort order in the report as
LotNumberSort
LotSortAlpha
you shouldn't need to add a grouping level just to get a correct sort.
Could it have anything to do with other sorting criteria in columns
before this sort?
yes. in a query, columns are sorted left to right, as Wayne said earlier,
and top to bottom in a report's Sorting And Grouping box. so if you have
other fields that are sorted ahead of the two we've been working with, then
that will of course affect the final sort order imposed on the recordset.
hth
Karl Burrows said:
Also, does this need to be an expression or just Group By?
Thanks!
Still having issues sorting on some reports. I do not use the field values
created in the query within the report (or should I?), so the numbers still
sort as text, even if I add grouping and sorting by LotSortAlpha. It works
on some reports and not on others. Very strange. Could it have
anything
to
do with other sorting criteria in columns before this sort?
try the following in your query:
add
LotNumberSort: Val([LotNumber])
then add
LotSortAlpha: [LotNumber]
to the RIGHT of LotNumberSort. sort both, ascending or descending as needed.
note: if you're doing any sorting/grouping in a report bound to this query,
don't bother to set a sort order in the query itself. just do the sort in
the report, listing the fields in order: LotNumberSort, then LotSortAlpha.
note: if there's any possibility that a record may have a Null value in the
LotNumber field, change the expression to
LotNumberSort: Val(Nz([LotNumber], 0))
hth
Karl Burrows said:
Still getting some issues with the sort:
Setup query with table field value LotClosings, no sort
Added column to the right called LotNumberSort: Val([LotNumber]) as
Expression
Added a second column to the left of LotNumberSort called SortLotAlpha:
Mid([LotNumber],Len(CStr(Val([LotNumber])))+1).
I also removed the grouping and sorting option for Lot Number in the report
and the sort is still backwards or random if there are text values in the
field value.
Did I do something wrong here?
Thanks!
This still has issues sorting
If you use the equation you currently have for the numeric sort then use
this one for the alpha sort, it will first sort by the number then by the
alpha characters after the number. "a" will come before "aa". It will work
with any number of characters or digits in front of the characters. The
equation in the Len statement tells the Mid() function to start after the
last numeric character and since a number of characters isn't specified
(that would be the 3rd parameter, but it has been left blank) then it will
continue to the end of the string. What this won't work for is if you change
the pattern of where the numbers and letters are, such as 1a2b.
--
Wayne Morgan
MS Access MVP
That makes sense, since the grouping was sorting by Lot Number, so
it
was
over riding the sort from the query.
Does this work for 1aaa, 1abc as well or just two text characters?