Add a page break to a report
Add a page break by using the page break control
In reports, you use a page break control to mark where you want to start a new page within a section. For example, if you want a report's title page and introductory message printed on separate pages, place a page break in the
report header
after the
controls that you want to appear on the title page and before the controls for the second page.
- Open the report in Design view.
- Click the Page Break tool
in the toolbox.
- Click where you want to place the page break. Place the page break above or below a control to avoid splitting data in that control.
Microsoft Access marks the page break with a short dotted line on the left edge of the report.
Notes
-
If you want each group or record in a report to start on a new page, set the ForceNewPage property of the
group header,
group footer, or
detail section.
-
The Catalog report in the Northwind sample database has an example of using a page break in the report header. To view this report, open the Northwind database in your
Microsoft Office folder's Samples folder, and then open the Catalog report in Design view.
Force a page break if a condition is met
You can force a page break in a report if a condition is met by setting the Visible property of a page
break control in a macro
or an event procedure.
- Open the report in Design view.
- Click the Page Break tool
in the toolbox.
- Click where you want to place the page break.
- Do one of the following:
Create a macro
- Click Properties
on
the toolbar, and specify a name for the page break control in the Name box.
- In the Database window, click Macros
under Objects.
- Click the New button on the Database window toolbar.
- In a blank action row,
click SetValue in the action list.
- Set the Item argument to the identifier for the Visible property of the page break control. For example, if the name of the control is
CondPgBreak, set the Item argument to [CondPgBreak].[Visible].
- Set the Expression argument to No.
- Click Save
to save the macro.
- In report Design view,
set the OnFormat property of the report's page header
section to the name of the macro.
-
This hides the page break control when the report starts formatting each page, so the page doesn't break.
- Create a second macro that sets the Visible property of the page break control to Yes when a conditional expression is met.
As you can see from the following example, to make a page break occur if the
Counter control in the detail section
is 10, set the detail section's OnFormat
property to the name of the second macro.
- Click Save to save the macro.
- Select the section where you placed the page break, and set
the section's OnFormat property to the name of the second macro. In
the preceding example, to make a page break occur if the Counter control
in the detail section is 10, set the detail section's OnFormat
property to the name of the second macro.
-
When the condition
is met, the page breaks. After the page is
broken, the macro attached to the page header hides the page break control
until the condition is met again.
Create
an event procedure
- Double-click the section selector of the page header.
- On the Event tab in the property sheet, click the OnFormat property.
- Click Build
next to
the property box to display the Choose Builder dialog box.
- Double-click Code Builder to display the event procedure Sub
and End Sub statements in the report module.
- In the event procedure, add an assignment statement that sets the Visible property of the page break
control to No. For example, if the name of the control is
CondPgBreak, add the following assignment statement:
Me![CondPgBreak].Visible = False
This hides the page break control when the report starts formatting each page, so the page doesn't break.
- In the Format event procedure of the section where you placed the page break, add
Microsoft
Visual Basic
code that sets the Visible property to Yes when a condition
is met. For example, to make the
detail section
break when the value of the Counter control reaches 10, add the following code to the Detail_Format event procedure:
If Me![Counter] = 10 Then
Me![CondPgBreak].Visible = True
End If