User defined Sort

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

Hi,

I have a query that has 10 fields and when run, would like
to allow the user to define which field to sort by and
which way to sort (ascending or descending). The result
would actually print out in a report. Any ideas?

Thanks
Jim
 
One way is to set the ControlSource of the GroupLevel, as Andy Baron
describes:
Sorting Records in a Report at run-time
at:
http://allenbrowne.com/ser-33.html

If there is nothing in the report's Sorting And Grouping dialog (View menu
in report design view), you can programmatically set the report's OrderBy
property in the Open event of the report.

Example: You have a form named "frmReport", with an option group named
"grpSortBy", and a check box named "chkDescending"

Private Sub Report_Open(Cancel As Integer)
Dim strSort As String

With Forms!frmReport
Select Case !grpSortBy
Case 1
strSort = "SomeField"
Case 2
strSort = "AnotherField"
'etc
End Select

If Len(strSort) > 0 Then
If !chkDescending.Value Then
strSort = strSort & " DESC"
End If
Me.OrderBy = strSort
Me.OrderByOn = True
End If
End With
End Sub
 
Back
Top