Changing Sort Order On Report Programatically

G

Guest

I have coded the following inside the report open event:
........
OrderByOn = True

If Not LTrim(RTrim(strSort)) = "" Then
Select Case strSortOrder
Case "D"
Me.OrderBy = strSort & " " & "DESC"
Case Else
Me.OrderBy = strSort
End Select
End If

It changes the sort order dynamically on some reports but not others. On
the reports that it does not work on, they have their own groups set up under
View/Sorting And Grouping. Once the sort order is set up on the report
itself under View/Sorting And Grouping, is it then not possible to change it
dynamically in the program ? As an alternative, I sorted the data in a query
and had the report read the query. I was then able to change the order
programatically. I noticed,however, that the report was not in the order of
the query. I am using filters on the report; the data file contains
different time periods and the report filters out to only one.

1) Is there a way to programatically change the sort order when the order
has been set in the report as listed above ?

2) Is there anyway to guarantee that the report using no sort order in
itself would use the order of the sorted query it is reading ?
 
A

Allen Browne

As you found, Access uses the Sorting And Grouping definitions first, and
only applies OrderBy after that.

Here's an alternative approach:
Sorting report records at runtime
at:
http://allenbrowne.com/ser-33.html

That answers your first q.
The answer to your 2nd q. is No: not reliably.
 
G

Guest

Thank you. It is what I expected.

Allen Browne said:
As you found, Access uses the Sorting And Grouping definitions first, and
only applies OrderBy after that.

Here's an alternative approach:
Sorting report records at runtime
at:
http://allenbrowne.com/ser-33.html

That answers your first q.
The answer to your 2nd q. is No: not reliably.
 

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

Top