Sorting records in a Report at runtime

        5 votes: *****     8,627 views      No comments
by Allen Browne, 20 April 2005    (for Access 95+)

Microsoft Access Tips for Serious Users

Provided by Andy Baron (

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: PoorYour rating: Not so goodYour rating: AverageYour rating: GoodYour 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...

E-mail (e-mail address will be kept private)

Comments require approval before being displayed on this page (allow 24 hours).