Sorting records in a Report at runtime

        5 votes: ****      8,305 views      0 comments
by Allen Browne, 20 April 2005    (Access 95+)

Microsoft Access Tips for Serious Users

Provided by Andy Baron (Andy_Baron@msn.com)


Sorting report records at runtime

Access reports do their own sorting based on the sort fields you specify in the Sorting and Grouping dialog of the report. The recordsource Order By clause is ignored.

Microsoft has a knowledgebase article that explains a technique for using setting the OrderBy property of a report by opening the report in design view (Article ID: Q146310).

I have always preferred to programmatically set the group levels of the report, with code like this in the Open event of the report:

    Select Case Forms!frmChooseSort!grpSort
    Case 1 'Name
        Me.GroupLevel(0).ControlSource = "LastName"
        Me.GroupLevel(1).ControlSource = "FirstName"
        Me.GroupLevel(2).ControlSource = "Company"
    Case 2 'Company
        Me.GroupLevel(0).ControlSource = "Company"
        Me.GroupLevel(1).ControlSource = "LastName"
        Me.GroupLevel(2).ControlSource = "FirstName"
    End Select

To make this work, you just need to make sure that you have set up the right number of grouping levels in the report's grouping and sorting dialog.


Home Index of tips Top

Rate this article:   Your rating: Poor Your rating: Not so good Your rating: Average Your rating: Good Your rating: Excellent


This is a cached tutorial, reproduced with permission.

Have your say - comment on this article.

What did you think of 'Sorting records in a Report at runtime'?

No comments yet.

Why not be the first to comment on this article?!

Have your say...

Name
E-mail (e-mail address will be kept private)
Comments
Verify Code
Verification Code


It may take 30 seconds after clicking submit - please be patient to avoid duplicate submissions.  

All comments must be approved before being displayed on this web page.  This process may take up to 24 hours.