Use a macro to force a page break in a report if a condition is met

Use a macro to force a page break in a report if a condition is met

  1. Open the report in Design view.

  2. In the toolbox, click Page Break , and then click in the report section where you want a conditional page break.

  3. Click Properties on the toolbar, and specify a name for the page break control in the Name box.

  4. Create a macro.

    How?

  5. In a blank action row, click SetValue in the action list.

  6. 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].

  7. Set the Expression argument to No.

  8. Click Save to save the macro.

  9. 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.

  10. Create a second macro that sets the Visible property of the page break control to Yes when a conditional expression is met.

Select an action to carry out when a condition that you specify is met

  1. Click Save to save the macro.

  2. 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.