Pass Sort Order from Subform to Report

G

Guest

I have a subform in datasheet view with 3 columns. The subform is based on a
query that sorts by Col1 then Col2 then Col3. I allow the users to use the
column Short Cut keys to re-sort the data in the different columns as they
see fit.

I also have a button on the form to run a report showing the data and the
report uses the same query as the subform.

I would like the report to display the records in the same order the user
has them set to on the form, how can I do this?

Thanks,
Ken
 
D

Dirk Goldgar

In
KPR said:
I have a subform in datasheet view with 3 columns. The subform is
based on a query that sorts by Col1 then Col2 then Col3. I allow the
users to use the column Short Cut keys to re-sort the data in the
different columns as they see fit.

I also have a button on the form to run a report showing the data and
the report uses the same query as the subform.

I would like the report to display the records in the same order the
user has them set to on the form, how can I do this?

First, bear in mind that any sort order imposed by specification in the
report's Sorting and Grouping dialog will override any sorting you do in
the query or in the report's OrderBy property. So if you've specified
Sorting and Grouping for your report, you'll have to modify the groups
you've specified. While that can be done programmatically at run time,
it's complicated.

If you don't need to do that, I believe you can let the report set its
own OrderBy property in its Open event. If you're using Access 2002 or
later, you could pass the OrderBy property of the subform via the
OpenArgs argument when you open the report. Or else you could have the
report check in its Open event to see if the form in question is loaded,
and pick up the OrderBy property from the subform. In either case, I
imagine you'll have to also set the report's OrderByOn property to True,
after you've set the OrderBy property.
 

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

Similar Threads


Top