ACC2000: How to Filter a Report Using a Form's FilterID: Q208548
|
This article describes how to create a command button on a filtered form that, when clicked, opens a report and applies the filter that is on the form to the report.
This example uses the sample database Northwind.mdb. The technique involves creating a new form and a new report. The form uses event procedures to apply a filter and to open the new report. The report uses the Filter property to apply the same filter that is used in the form.
Name: cmdOpenReport
Caption: Open Report
OnClick: [Event Procedure]
Private Sub cmdOpenReport_Click()
If Me.Filter = "" Then
MsgBox "Apply a filter to the form first."
Else
DoCmd.OpenReport "rptCustomers", acViewPreview, , Me.Filter
End If
End Sub
Name: cmdClearFilter
Caption: Clear Filter
OnClick: [Event Procedure]
Private Sub cmdClearFilter_Click()
Me.Filter = ""
End Sub
Name: cmdClose
Caption: Close
OnClick: [Event Procedure]
Private Sub cmdClose_Click()
DoCmd.Close acForm, Me.Form.Name
End Sub
OnOpen: [Event Procedure]
OnClose: [Event Procedure]
Private Sub Form_Open(Cancel as Integer)
Me.Filter = ""
End Sub
Private Sub Form_Close()
DoCmd.Close acReport, "rptCustomers"
End Sub
For more information about the Filter property, click Microsoft Access Help on the
Help menu, type "Filter Property" in the Office Assistant or the Answer Wizard,
and then click Search to view the topics returned.
For more information about Filter By Form, click Microsoft Access Help on the
Help menu, type "Modify a filter in the Filter By Form window in a table, query, or form" in the Office Assistant or the Answer Wizard,
and then click Search to view the topics returned.
For more information about Filter By Selection, click Microsoft Access Help on the
Help menu, type "Filter records by selecting values in a form or datasheet" in the Office Assistant or the Answer Wizard,
and then click Search to view the topics returned.
Additional query words:
Keywords : kbdta FmrCdbeh
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: June 10, 1999