Changing Sort Order On Report Programatically

  • Follow


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 ?
0
Reply Utf 6/28/2007 12:44:01 AM

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.

-- 
Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"rmcompute" <rmcompute@discussions.microsoft.com> wrote in message
news:90F5E438-AFE2-4F62-9119-F45B358F97E2@microsoft.com...
>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 ? 

0
Reply Allen 6/28/2007 1:30:37 AM


Thank you.  It is what I expected.

"Allen Browne" wrote:

> 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.
> 
> -- 
> Allen Browne - Microsoft MVP.  Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
> 
> "rmcompute" <rmcompute@discussions.microsoft.com> wrote in message
> news:90F5E438-AFE2-4F62-9119-F45B358F97E2@microsoft.com...
> >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 ? 
> 
> 
0
Reply Utf 6/28/2007 10:30:01 PM

2 Replies
998 Views

(page loaded in 0.36 seconds)

Similiar Articles:
















7/25/2012 10:15:43 PM


Reply: