quizkiwi
Oct 24 2006, 12:29 PM
I would like to open a report and sort the records. Is there a way to do this?
I have the command:
CODE
DoCmd.OpenReport Me.cboWhichReport, acViewPreview, , Filter
This works for supplying where criteria, but not sorting or at least not the way I have been trying.
Thanks
jmcwk
Oct 24 2006, 01:17 PM
Look at sorting and grouping within the report itself from the Sorting and Grouping Icon in the Toolbar
quizkiwi
Oct 24 2006, 05:34 PM
Yes, but if the the filter I am applying in the code needs to change the predefined sort order...what do I do?
jmcwk
Oct 24 2006, 06:12 PM
Not to sure i can help you but what code are you using now?
quizkiwi
Oct 24 2006, 07:09 PM
CODE
DoCmd.OpenReport Me.cboWhichReport, acViewPreview, , Filter
So i thought I could set filter to be the sort clause...
CODE
Filter = "ORDER BY Field1"
But I think that the Where clause requires it to be simply a where statement and not an order by statement
niesz
Oct 24 2006, 07:12 PM
The filter has nothing to do with the Sort Order. Sorting and Grouping are handled within the report in the section John mentioned. How does filtering a report impact the sort order? All you are doing is limiting the records.
quizkiwi
Oct 24 2006, 07:32 PM
right, but can I do the sorting/grouping from the code of a form which is opening the report?
niesz
Oct 24 2006, 07:44 PM
If you needed this functionality I would write this code in the Report's OnOpen event and look to the form to get the options needed. See the following VBA properties/methods:
CreateGroupLevel method
GroupOn property
GroupInterval property
GroupLevel property
KeepTogether property
SortOrder property
Some of these may only be able to be set while the report is in Design view.
Alternatively, you could just create two or more versions of the same report and call the appropriate one from the form.
quizkiwi
Oct 24 2006, 08:06 PM
okay, that is an acceptable option. I will try the code first and then resort to the second report. Thanks
niesz
Oct 24 2006, 08:13 PM
NP.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.