The idea is to set a public string variable with the filter you need before
the PrintOut, and then use the Open event of the report to apply that as the
report's filter.
Please note that the page numbers and filter do interact. For example, if
you ask for just pages 2 - 5 of the report, and filter it to the orders for
customer 99, then you will get pages 2 - 5 of the filtered report (which may
not be pages 2 - 5 of the report if it shows all customers.)
Steps:
1. Choose the Modules tab of the Database window.
Click New. Access opens a module.
Just below the Option statements at the top, enter:
Public gstrReportFilter As String
Save the module as (say) Module1.
Close.
2. Open your report in design view.
Open the Properties box (view menu.)
The Title of the Properties box must read Report (so you are looking at the
properties of the report, not those of a text box or section.)
On the Event tab, set the On Open property to:
[Event Procedure]
Click the Build button (...) beside this.
Access opens the code window.
Between the "Private Sub..." and "End Sub" lines set this up:
Private Sub Report_Open(Cancel As Integer)
If gstrReportFilter <> vbNullString Then
Me.Filter = gstrReportFilter
Me.FilterOn = True
gstrReportFilter = vbNullString
End If
End Sub
3. In the code that calls the PrintOut, set the global string to the filter
you need first. This example prints out just pages 2 to 5 of the report
after it is filtered to customer 99.
Private Sub Print_Click()
gstrReportFilter = "[CustomerID] = 99"
DoCmd.PrintOut acPages, 2,5
End Sub
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Martha65 said:
I'm afraid I am not a big expert in Access. Could you give me a little
more
details on how and where to place a Filter? Will this require a query or
expression?