Use Visual Basic 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.
- Open the report's PageHeader_Format event procedure.
How?
- 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 Visual Basic code that sets the Visible property to Yes when a condition is met. For example, suppose you want a page break to occur in the detail section of the report if the value of the Counter control is 10 so that the first 10 records will print on the first page. Add the following code to the Detail_Format event procedure:
If Me![Counter] = 10 Then
Me![CondPgBreak].Visible = True
End If
When the condition is met, the page breaks. After the page is broken, the event procedure attached to the page header hides the page break control until the condition is met again.