Certain types of reports require that each record be printed a specific
number of times. These reports include labels that are used for picking,
shipping and invoicing, or tear-off forms that are meant for multiple
recipients.
The following example demonstrates how to use a text box on an unbound form
to specify the number of times each record should be printed in the report.
Start Microsoft Access and open the sample database Northwind.mdb (or
NWIND.MDB if you are using Microsoft Access version 2.0).
Click the Reports tab and then click New.
In the New Report dialog box, click AutoReport: Columnar and base the
report on the Shippers table. Then click OK.
If you are using Microsoft Access version 2.0, click Shippers in the
Select A Table/Query drop-down list in the New Report dialog box; then
click the Report Wizards button. In the Report Wizards dialog box,
click AutoReport, and then click OK.
Save the report as rptRepeatRecs.
Open the rptRepeatRecs report in Design view.
On the View menu, click Code.
Under Option Compare Database, type the following statements:
Option Explicit
Dim intPrintCounter As Integer
Dim intNumberRepeats As Integer
Note that if you are using Microsoft Access version 7.0 or later,
Option Explicit may already exist in the Declarations section.
Close the module.
On the Edit menu, click Select Report.
On the View menu, click Properties.
Click the OnOpen property box and then click the Build button (...) to
the right.
In the Choose Builder dialog box, click Code Builder, and then click
OK.
Type the following code:
Private Sub Report_Open(Cancel As Integer)
intPrintCounter = 1
intNumberRepeats = Forms!PrintForm!TimesToRepeatRecord
End Sub
Close the module.
Click the horizontal Detail bar. If the Detail section's property
sheet is not already visible, click Properties on the View menu.
Click the OnPrint property box, and then click the Build button (...)
to the right.
In the Choose Builder dialog box, click Code Builder, and then click
OK.
Type the following code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
' Note: intNumberRepeats and intPrintCounter are initialized
' in the report's OnOpen event.
If intPrintCounter < intNumberRepeats Then
intPrintCounter = intPrintCounter + 1
' Do not advance to the next record.
Me.NextRecord = False
Else
' Reset intPrintCounter and advance to next record.
intPrintCounter = 1
Me.NextRecord = True
End If
End Sub
Note that this procedure may be called Detail1_Print in Microsoft
Access version 2.0.
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.