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
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Helen FeddemaCommented:
I would do the sorting (and filtering, if that is needed) in code running from a control that opens the report, such as the Report button on my New Style Main Menu sample database.  Create a saved query using the selected sort, and make that query the record source of the subreport.  Here is a link for the Access Archon article featuring this database:
http://www.helenfeddema.com/Files/accarch212.zip
and here is a screen shot of the main menu:
New Style main menu
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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.
0
Jeffrey CoachmanMIS LiasonCommented:
Something like this worked OK for me...

Obviously there will be other ways to do this, ...but sometimes I just like to manipulate the sorting in the Report's recordsource
 (if no grouping levels are present)
Database222.accdb
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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.
0
SteveL13Author Commented:
Boag2000,

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

--Steve
0
Jeffrey CoachmanMIS LiasonCommented:
<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
0
Jeffrey CoachmanMIS LiasonCommented:
0
Jeffrey CoachmanMIS LiasonCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.