How do I print a selection of pages from Access Database report?

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

Guest

I have a multiple page report in an Access Database. I want the ability to
pick and choose which pages to print by adding a check-box either in a form
or the report itself. Is this possible?
 
If you preview the report, you can choose Print from the File menu, and
enter the page(s) to print.
 
Hi Allen, thanks for your help. I tried that. It just became time consuming
because not all page(s) fall in sequence of each other. Therefore, every
time I print 1 or 2 pages, I have to return to the report and find the next
page(s) I want to print; return to the File/Print and print the next
selection, and so forth. My other option would be to print the whole report
than dicard of the pages I don't need, but I mind the waste. :).
 
Your other option is to use PrintOut rather than OpenReport.

PrintOut lets you specify the page range.
It does not have a WhereCondition.
You can work around that by setting the Filter property of the report in its
Open event.
 
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?
 
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
 
Thank you, Allen. I will try this.

Allen Browne said:
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?
 
Back
Top