Use a macro to force a page break in a report if a condition is met
- Open the report in Design view.
- In the toolbox, click Page Break , and then click in the report section where you want a conditional page break.
- Click Properties on the toolbar, and specify a name for the page break control in the Name box.
- Create a macro.
How?
- 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.
- 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.