INF: KeepTogether for Groups and Sections

PSS ID Number: Q104757
Article last modified on 09-29-1993

1.00 1.10
WINDOWS

---------------------------------------------------------------------
The information in this article applies to:

 - Microsoft Access versions 1.0 and 1.1
 - Microsoft Access Distribution Kit version 1.1
---------------------------------------------------------------------

SUMMARY
=======
Although Microsoft Access provides a KeepTogether property for
ensuring that a section of data will stay together on a page, there is
no property for doing the same to keep a group of sections together on
a page.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools
provided with Microsoft Access. For more information on Access Basic,
please refer to the "Introduction to Programming" manual.

MORE INFORMATION
================
The KeepTogether property in a section ensures that all the data in a
section prints together on one page as opposed to splitting a section
between two pages. This feature does not exist for keeping entire
groups or sections together on one page.
If the size of a section is predictable, such as a header or footer,
the problem can be solved by forcing a page break in the section when
it is determined that there is not enough page left to accommodate the
size of the section. This can be done by including a hidden page break
at the top of the section, checking to see where on the page the data
will print to, and making the page break visible if there is not
enough room.
This procedure is outlined in the steps below:
1. Create a new module by selecting New from the File
   menu and choosing Module.
2. Copy the function BreakOnTwip (listed below) into the module
   window.
3. Open the report in design mode.
4. Drag and drop a page break control from the toolbox to the top of
   the desired section. Change the ControlName property for this page
   break control to: MyPageBrk
5  Click on the section bar that you want to force the page break on.
6. Display the Property sheet of the report by selecting Properties
   from the View menu.
7. Call the function from the OnFormat property for the section:
      OnFormat: =BreakOnTwip(12000,"MyPageBrk")
8. Determine how many twips down on a page you want to go before
   effecting the page break. If you do not know, try the value
   12000.
   Function BreakOnTwip (WhereToBreak%, PageBreakName$)
      Dim WhatReport As Report
      Set WhatReport = Screen.ActiveReport
      If WhatReport.Top >= WhereToBreak Then
         WhatReport(PageBreakName).Visible = True
      Else
         WhatReport(PageBreakName).Visible = False
      End If
   End Function
9. Run the report.
If you notice that the page break is occurring too high on the page,
allowing the section to print before breaking, try repeating steps 5
through 8 above and increasing the <Twip to Break On> value by
increments of 50 until you achieve the desired result.
Another method to achieve the same results is described in the
Knowledge Base article titled: "How to Avoid Abandoned Group Headers
in Reports."

Additional reference words: 1.00 1.10
KBCategory:
KBSubcategory: RptsPrp
Copyright Microsoft Corporation 1993.