Introduction to Grouping Records
Creating a Group Header
To create a group of records on a report, you have various options. You can let the Report Wizard assist you or you can work manually. If you want to create the group yourself, first open the report in Design View and specify, or make sure, its Record Source has a table. Then:
This would add a new section titled Group, Sort, and Total under the report. At any time, to close the Grouping window, click its Close button:
One of the buttons in the new section is titled Add a Group. To create a new group, click that button. This would change the contents of the window and display a new button with a popup window that shows the fields of the table specified as the Record Source.
From the popup window, click the name of the field you want to use as the group leader. Here is an example:
This would add a new bar and section to the report above the Detail bar. The bar of the new section would display the name of the field followed by Header. Here is an example:
Also, under the report, the contents of the Group, Sort, and Total window would be changed into a new bar that displays the name of the field that was selected.
Practical Learning: Creating a Group
Designing a Group
After creating a group, you can add, or continue to add, the fields to the report. One of the actions you can take, but which is not required, is to add the field that holds the same name as the new section. Here is an example:
If you design the form and group that way, when the report prints, the name of the group would show before the related records: remember that the report bars do not show on the printed paper. The alternative is to put the control of the group name in the Page Header section (or another section of your choice).
After adding the field in a section, you can add, or you can continue adding, the other fields. Those other fields should be added in the Detail section or the section below the group header. If you include their labels, these labels would show for each field:
As an alternative, you can put the labels of the child fields in the section of the group header, and put the controls in the section under the group leader. Another aspect of design is that you should provide room only as much as necessary for each related record. Here is an example:
When the report displays or when it prints, all related records should show appropriately:
Still, if each record has some detail, such as a comment or a calculation you want to add, you can/should include it in the Detail section, probably under the other fields.
Practical Learning: Designing a Group
When to Display a Section
By default, after adding a section to a report, the section would show in Design View and its contents would appear in the other views. If you want, you can hide the section in either the Design View or the other views. This characteristic is controlled by the Display When enumerated property. To apply it, display the report in Design View and access the Property Sheet of the section for which you want to control this characteristic. Click either the Format or the All tab.
The Display When property has three options:
Practical Learning: Specifying When to Display a Section
Adding a Sub-Group to a Group
In a certain table, you may have records that can be categorized. Then, inside of each category, there may be a sub-category. When creating a report for such a table, you can create one group, then create another group inside of that group.
To create a sub-group, start the report as we learned previously. In the Group, Sort, and Total window, below the first bar, there would be a new Add a Group button and a dotted curved line joining them:
To create a sub-group, click the Add a Group button to display the list of fields and click a field from that list:
A new section would be added below the main one and it would have the same name of the field that was added, followed by Header:
Notice that below the report, a bar for the new group is added and it has its own Add a Group button, which indicates that, if necessary, you can create another sub-group. You can continue the same approach to create as many sub-sections as you judge necessary.
When designing the report, in the main section, you should add only its own field. In the group under it, you can add the field of that group and the labels of the related records if that section does not have its own sub-group. Then, in the Detail section, add the necessary controls. Here is an example:
Practical Learning: Creating Objects
Removing a Group
If you have a group you don't like on a report, you can get rid of it. To remove a group, under the report, click the Delete button that corresponds to it. You would receive a warning so you can make your final decision. If you delete a sub-group, only its section would be removed from the report. If you delete a group that has one or more sub-groups, its section and its sub-sections would be removed from the report.
Forcing a New Page
When creating a report, you add the fields of the records as you see fit in the desired sections and groups. As seen with the Keep Together Boolean property, you can exercise some control on the number of records to print on one page based on the number of fields of each record. We saw that if many records could fit on one page, then they would be grouped on that one page. In some cases, you may want each record on its own page, even if the record has only a few values, even if many records can fit on one page. Displaying each record on its own page is referred to as forcing a new page.
The ability to force each record on its own page is controlled by the Force New Page enumerated property. Its values are:
Practical Learning: Creating a Catalog