DoCmd.openreport - sort option?

G

Guest

Hi,
I currently have a form that contains 4 check boxes and a command button
(generate report), one for each field.
name,address,city,country.
When the command button is clicked, i want to open the report and sort by
whatever check box is clicked, ie: DoCmd.OpenReport stDocName, acViewPreview
(then open the report sorted by name field). is there an arguement that can
be entered at the docmd line to tell the report how to open or can a macro do
this

Thanks for help
 
N

Nikos Yannacopoulos

Use some simple code in the report's Open event to check the checkboxes
on the form, and set the report's OrderBy property accordingly, then set
the OrderByOn property. Sample code:

Private Sub Report_Open(Cancel As Integer)
If chkName + chkAddress + chkCity + chkCountry = 0 Then Exit Sub
If Forms![MyForm]!chkName Then
strOrder = "fldName"
End If
If Forms![MyForm]!chkAddress Then
If Len(strOrder) > 0 Then strOrder = strOrder & ", "
strOrder = strOrder & "fldAddress"
End If
If Forms![MyForm]!chkCity Then
If Len(strOrder) > 0 Then strOrder = strOrder & ", "
strOrder = strOrder & "fldCity"
End If
If Forms![MyForm]!chkCountry Then
If Len(strOrder) > 0 Then strOrder = strOrder & ", "
strOrder = strOrder & "fldCountry"
End If
Me.OrderBy = strOrder
Me.OrderByOn
End Sub

HTH,
Nikos
 

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

Top