Open Form Print Preview with chosen sort (1 Viewer)

Kronix

Registered User.
Local time
Today, 12:25
Joined
Nov 2, 2017
Messages
102
I have a subform with a datasheet query. I have a button that pops up a window of the subform in Print Preview. I want the sort that is chosen in the subform (on the fly using the column arrows or the sort and filter area of the Start ribbon) to show up in the Print Preview. Using DoCmd.OpenQuery didn't work -- it would always default to the default query sort. Since the sort that was chosen is saved until the next time I open the form, I figured it was being saved in the Form settings and I could use DoCmd.OpenForm to open a print preview that reflects the changes.

Well, I'm halfway there because DoCmd.OpenForm print preview will only reflect the changes to the sort that were made before I last closed the form with the subform datasheet in it. This must be because Access is saving the selected sort only after the subform is closed.

I want to make Access save the form's sort order in VBA right before the print preview is opened with DoCmd.OpenForm. But how do I do this? DoCmd.Save does not work on the subform -- the command only recognizes the subform name if it is opened in its own window, not as a subform. Saving the main form doesn't affect anything. And the OrderByOn property does not even exist for the subform.
 

isladogs

MVP / VIP
Local time
Today, 11:25
Joined
Jan 14, 2017
Messages
18,235
I have a subform with a datasheet query. I have a button that pops up a window of the subform in Print Preview.

Forms aren't designed to be printed. Use a report instead

If you are opening a popup report version of the subform, you set the sort (or grouping order within the report
In design view, right click and select Sorting and Grouping then setup the sort order as required
 

Users who are viewing this thread

Top Bottom