ACC: How to Filter a Report Using a Form's FilterID: Q145591
|
Moderate: Requires basic macro, coding, and interoperability skills.
This article describes how to create a button on a filtered form that opens
a report and applies the same filter that is on the form to the report.
NOTE: This article explains a technique demonstrated in the sample
files, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0)
and RptSmp97.exe (for Microsoft Access 97). For information about how
to obtain these sample files, please see the following articles in the
Microsoft Knowledge Base:
Q145777 ACC95: Microsoft Access Sample Reports Available on MSL
Q175072 ACC97: Microsoft Access 97 Sample Reports Available on MSL
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", A_PREVIEW, , 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
Set the form's OnClose [Event Procedure] as follows:
Private Sub Form_Close()
DoCmd.Close acReport, "rptCustomers"
End Sub
For more information about the Filter property, search the Help Index for
"Filter Property," or ask the Microsoft Access 97 Office Assistant.
For more information about Filter By Form or Filter By Selection, search
the Help Index for "Filter By Form" or "Filter By Selection," or ask the
Microsoft Access 97 Office Assistant.
Keywords : FmrCdbeh
Version : 7.0 97
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 15, 1999