To create an event procedure that is run when the Print event occurs, set the OnPrint property to [Event Procedure], and click the Build button.
Private Sub sectionname_Print (Cancel As Integer, PrintCount As Integer)
The Print event procedure uses the following arguments.
Argument |
Description |
sectionname |
A string that is the name of the section affected by the Print event procedure. |
Cancel |
The setting determines if the printing of the section occurs. Setting the Cancel argument to True (-1) cancels printing of the section. |
PrintCount |
An integer value that specifies whether the Print event has occurred more than once for a record. For example, if part of a record is printed on one page and the rest is printed on the next page, the Print event occurs twice, and the PrintCount argument is set to 2. |
To cancel printing of the section, you set the Cancel argument to True (-1) or use the CancelEvent method of the DoCmd object. Microsoft Access prints a blank area on the page where the section would have been. You can use CancelEvent to skip a record in a report and leave a blank area on the page in its place when the report is printed.
Note You can’t use a Print event procedure to set properties for any object.
Print Event — Macros.
This example checks the PrintCount argument to determine the number of times the Print event has occurred. If it has occurred more than once, the Print event is canceled for the section.
To try the following example, add the following code to the Declarations section of a report that contains a section named CustomerDetail.
Private Sub CustomerDetail_Print (Cancel As Integer, _ PrintCount As Integer) If PrintCount > 1 Then Cancel = TrueSub