KeepTogether Property -- Groups

Applies To

Report, Sorting and Grouping Box.

Description

You can use the KeepTogether property in reports 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 always to be printed on the same page with the first detail section.

Setting

The KeepTogether property uses the following settings.

Setting

Description

Visual Basic

No

(Default) Prints the group without keeping the group header, detail section, and group footer on the same page.

0

Whole Group

Prints the group header, detail section, and group footer on the same page.

1

With First Detail

Prints the group header on a page only if it can also print the first detail record.

2


You can set the KeepTogether property in a report’s Sorting and Grouping box, a macro, or Visual Basic.

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

Remarks

To set the KeepTogether property to a value other than No, you must set the GroupHeader or GroupFooter property 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 to Whole Group and a group is too large to fit on one page, Microsoft Access will ignore the setting for that group. Similarly, if you choose With First Detail and either the group header or detail record is too large to fit on one page, the setting will be ignored.

See Also

CreateGroupLevel Function; GroupHeader, GroupFooter Properties; GroupInterval Property; GroupLevel Property; GroupOn Property; KeepTogether Property — Sections; SortOrder Property.

Example

The following example sets the sort order and group properties for the first group level in the Products By Category report.


Sub Report_Open()
    ' Set SortOrder property to descending order.
    Reports![Products by Category].GroupLevel(0).SortOrder = True
    ' Set GroupOn property to Prefix Characters.
    Reports![Products by Category].GroupLevel(0).GroupOn = 1
    ' Set GroupInterval property to 1.
    Reports![Products by Category].GroupLevel(0).GroupInterval = 1
    ' Set KeepTogether property to With First Detail.
    Reports![Products by Category].GroupLevel(0).KeepTogether = 2Sub