Report Sorting help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created a form (frmFileIndex) that shows the user a listing of “File
Index Numbers†and associated “File Namesâ€. Above each of these two fields,
I have placed a command button that allows the user to sort on either column.
This provides a numeric looking listing (sorting by “File Index Numberâ€) or
an alphabetized listing (sorting by “File Nameâ€). A third command button is
placed on this form that allows the user to print out a report of the File
Index table (rptFileIndex).

Can anyone provide me with some assistance in coding that would have the
report print out in the sorted order selected by the user above. My failed
attempts had me trying coding that would look like this below, but can’t seem
to get it to work:

Private Sub Report_Open(Cancel As Integer)
If Forms![frmFileIndex]!Sort_by_File_Name Then
strOrder = "strFileNumber"
Else
strOrder = "strFileName"
End If
Me.OrderBy = strOrder
Me.OrderByOn
End Sub

Any help would be greatly appreciated,
Coleman
 
If you build a filter based upon the user selection of sort order and set it
equal to OpenArgs it will carry to the report. (a good example is on Allen
Brown's website http://allenbrowne.com/tips.html ). Place a text box on the
report and set it's control source to =OpenArgs; you can the hide it if you
want by Visible = False.
The following is how I carry the users selection of the sort order to
reports (it is in the OnOpen event of the report) in my applications. The
IsNull establishes a default sort order if the user does not choose a sort
order.

Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
'If user has not selected any filtering criteria then sort data by Company
Name, County, City
If IsNull(Me.OpenArgs) Then
Me.txtOpenArgs.Visible = False
Me.OrderBy = "[strCompany] & [strCoCity]"
Me.OrderByOn = True
Else
'If user has selected filtering criteria then sort data by County, Company
Name, City
Me.OrderBy = "[strCountyName] & [strCompany] & [strCoCity]"
Me.OrderByOn = True
End If
End Sub

The OpenArgs carries the filter description from the form to the report.

HTH
scruffy
 

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

Back
Top