Keep a Report from Breaking at an Inappropriate Place
Problem
On some of your reports, you use the Keep Together property to keep a whole group together or to ensure that a group header won’t print without at least one detail item. When detail items are long, you may not want to keep an entire detail item together; however, you do want to have a reasonable number of lines under the header so that the header won’t be the last line on the report page. How do you make a report start a new page instead of printing the group header with just a single detail line at the bottom of a page?
Solution
You can use an event procedure called from a report’s Format event to evaluate the length of a report page before it actually prints and take an action (in this case, activating a page break control) only if certain criteria are met. This technique uses the acbConditionalBreak function and a page break control. This solution demonstrates how to use acbConditionalBreak to force a page break if there is not enough room to print at least one line of text from the detail section under a group header.
Open 03-14.MDB
and print the report
rptBadBreaks. This typical business-address report, which has its
detail section’s KeepTogether property set to Yes, occasionally
prints a page with the Category group header as the last line of the
page, as shown in Figure 3-33.
Figure 3-33. Page 2 of rptBadBreaks ...
Get Access Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.