You can control the number of records printed per page in a report by
setting the
Visible property for page breaks. The following example
demonstrates how to print three records per page in a report:
- Start Microsoft Access and open the sample database Northwind.mdb.
- Follow these steps to create a report called Report1 based on the Suppliers table:
- In the Database window, click Reports, and then click New.
- Select the Suppliers table, and then click OK.
- Add the following text boxes to the Detail section of the report, and place them on one line:
Report: Report1
--------------------------
Caption: TestReport
ControlSource: Suppliers
Text Box:
Name: Address
ControlSource: Address
Text Box:
Name: City
ControlSource: City
Text Box:
Name: Region
ControlSource: Region
- Add a text box with the following properties to the Detail section. Place the text box directly above the Address control. This
control acts as a counter for the number of records in the report:
Text Box:
-----------------------
Name: Counter
ControlSource: =1
Visible: No
RunningSum: Over All
- Open the toolbox if it is not already open, click Page Break, and then add a page break control to the lower-left corner of the detail section. Place it directly below the Address control, and set the Name property to PageBreak.
- In the Detail section, set the OnFormat property to the following Event Procedure:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![Counter] Mod 3 = 0 Then Me![PageBreak].Visible = True _
Else Me![PageBreak].Visible = False
End Sub
- Minimize the amount of white space by moving the Page Footer bar to directly below the PageBreak control.
- Preview the report.
The first page of the report should contain the following three records:
Address City Region
----------------------------------------
49 Gilbert St. London
P.O. Box 78934 New Orleans LA
707 Oxford Rd. Ann Arbor MI
If the last record is missing or is only partially displayed, the
PageBreak control is not down far enough in the report's
Detail section.
NOTE: You can modify this example to print any number of records per page by changing the code in the
OnFormat property of the
Detail section from "mod 3" to "mod
x" where
x is the number of records you want to print per page. For example, if you want to print 11 records per page, change the expression to read:
If Me![Counter] Mod 11 = 0 Then Me![PageBreak].Visible = True _
Else Me![PageBreak].Visible = False