This article was previously published under Q209006
Moderate: Requires basic macro, coding, and interoperability skills.
This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).
This article describes a method that you can use to control the number ofrecords printed per page in a report.
You can control the number of records printed per page in a report bysetting the Visible property for page breaks. The following exampledemonstrates 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 = FalseEnd 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. LondonP.O. Box 78934 New Orleans LA707 Oxford Rd. Ann Arbor MI
If the last record is missing or is only partially displayed, thePageBreak 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
For more information about the SetValue action, click Microsoft Access Help on the Help menu, type setvalue action in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
For more information about the Visible property, click Microsoft Access Help on the Help menu, type visible property in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.
For more information about the Page Break control, click Microsoft Access Help on the Help menu, type page break control properties in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.