Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

How sort records in a subreport based on the selection in a combobox on a form

Is there a way to sort the records in the detail section of a subreport based on the selection in a combobox on a form.

There are three choices:  Category, Location , and Room.  Each of this is a field in the query which is the reports recordsource.

I don't know if some code in the onopen event of the report would work?

--Steve
ASKER CERTIFIED SOLUTION
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You'll have to do it in the OnOpen of the report.  Report's ignore any sorting in an underlying data source.  Set the OrderBy property, and the OrderOnLoad property to True.

Jim.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note too that sorting is impacted by Groups as well - so if you're Grouping by FieldA but tell Access to Sort by FieldB, then your records would show on the form "sorted" for FieldA, and for each of those Groups, the records would then be "sorted" by FieldB.
Avatar of SteveL13

ASKER

Boag2000,

I mistakenly accepted your suggestion before I realized that I could not download your example.  Could you report it for me please?

--Steve
<I could not download your example. >
Could not download it, ...or could not open it...?

In any event here it is again, in access 2003 mdb format
Steve,

Note that I used the recordsource here.

What the other experts posted about using the OrderBy Property is the more used technique.
For whatever reason,  I was having trouble with Ordeby in a SubReport, (opened by a form)

So my old fallback is to just grab the Recordsouce and sort that instead.
What this meas is that you ever add a sort in the report itself, the recordsouce sort will be ignored (as Jim States)

Finally note that this may all change if your report includes grouping levels.

So play around with this and also play around with Ordeby.
again, I can think of about half a dozen approaches to this...

JeffCoachman