KeepTogether Property

Microsoft Access Visual Basic

Show All

KeepTogether Property

       

KeepTogether property as it applies to the Section object.

You can use the KeepTogether property for a section to print a form or report section all on one page. For example, you might have a group of related information that you don't want printed across two pages. The KeepTogether property applies only to form and report sections (except page headers and page footers). Read/write Boolean.

expression.KeepTogether

expression   Required. An expression that returns one of the above objects.

Remarks

The KeepTogether property for a section uses the following settings.
Setting Visual Basic Description
Yes True   Microsoft Access starts printing the section at the top of the next page if it can't print the entire section on the current page.
No False (Default) Microsoft Access prints as much of the section as possible on the current page and prints the rest on the next page.

You can set this property by using the section's property sheet, a macro, or Visual Basic.

You can set the KeepTogether property for a section only in form Design view or report Design view.

Usually, when a page break occurs while a section is being printed, Microsoft Access continues printing the section on the next page. By using the section's KeepTogether property, you can print the section all on one page. If a section is longer than one page, Microsoft Access starts printing it on the next page and continues on the following page.

If the KeepTogether property for a group is set to Whole Group or With First Detail and the KeepTogether property for a section is set to No, the KeepTogether property setting for the section is ignored.

KeepTogether property as it applies to the GroupLevel object.

You can use the KeepTogether property for a group in a report to keep parts of a group — including the group header, detail section, and group footer — together on the same page. For example, you might want a group header to always be printed on the same page with the first detail section. Read/write Byte.

expression.KeepTogether

expression   Required. An expression that returns one of the above objects.

Remarks

The KeepTogether property for a group uses the following settings.

Setting Visual Basic Description
No 0 (Default) Prints the group without keeping the group header, detail section, and group footer on the same page.
Whole Group 1 Prints the group header, detail section, and group footer on the same page.
With First Detail 2 Prints the group header on a page only if it can also print the first detail record.

You can set the KeepTogether property for a group by using the Sorting And Grouping box, a macro, or Visual Basic.

In Visual Basic, you set the KeepTogether property for a group in report Design view or the Open event procedure of a report by using the GroupLevel property.

To set the KeepTogether property for a group to a value other than No, you must set the GroupHeader or GroupFooter property or both to Yes for the selected field or expression.

A group includes the group header, detail section, and group footer. If you set the KeepTogether property for a group to Whole Group and the group is too large to fit on one page, Microsoft Access will ignore the setting for that group. Similarly, if you set this property to With First Detail and either the group header or detail record is too large to fit on one page, the setting will be ignored.

If the KeepTogether property for a section is set to No and the KeepTogether property for a group is set to Whole Group or With First Detail, the KeepTogether property setting for the section is ignored.

Example

As it applies to the Section object.

The following example returns the KeepTogether property setting for a report's detail section and assigns the value to the intGetVal variable.

Dim intGetVal As Integer
intGetVal = Me.Section(acDetail).KeepTogether