Application.CreateGroupLevel method (Access)
Use the CreateGroupLevel method to specify a field or expression on which to group or sort data in a report.
Syntax
expression.CreateGroupLevel (ReportName, Expression, Header, Footer)
expression A variable that represents an Application object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
ReportName | Required | String | The name of the report that will contain the new group level. |
Expression | Required | String | The field or expression to sort or group on. |
Header | Required | Integer | Indicates that a field or expression will have an associated group header. If the Header argument is True (1), the field or expression will have a group header. If the Header argument is False (0), the field or expression won't. You can create a header by setting the argument to True. |
Footer | Required | Integer | Indicates a field or expression will have an associated group footer. If the Footer argument is True (1), the field or expression will have a group footer. If the Footer argument is False (0), the field or expression won't. You can create a footer by setting the argument to True. |
Return value
Long
Remarks
For example, suppose you are building a custom wizard that provides the user with a choice of fields on which to group data when designing a report. Call the CreateGroupLevel method from your wizard to create the appropriate groups according to the user's choice.
Use the CreateGroupLevel method when designing a wizard that creates a report with groups or totals. The CreateGroupLevel method groups or sorts data on the specified field or expression and creates a header and/or footer for the group level.
The CreateGroupLevel method is available only in report Design view.
Microsoft Access uses the GroupLevel property array to keep track of the group levels created for a report. The CreateGroupLevel method adds a new group level to the array, based on the expression argument. The CreateGroupLevel method then returns an index value that represents the new group level's position in the array. The first field or expression that you sort or group on is level 0, the second is level 1, and so on. You can have up to ten group levels in a report (0 to 9).
When you specify that either the Header or Footer argument, or both, is True, the GroupHeader and GroupFooter properties in a report are set to Yes, and a header and/or footer is created for the group level.
After a header or footer is created, you can set other GroupLevel properties: GroupOn, GroupInterval, and KeepTogether.
Note
If your wizard creates group levels in a new or existing report, it must open the report in Design view.
Example
The following example creates a group level on an OrderDate field on a report called OrderReport. The report on which the group level is to be created must be open in Design view. Because the Header and Footer arguments are set to True (1), the method creates both the header and footer for the group level. The header and footer are then sized.
Sub CreateGL()
Dim varGroupLevel As Variant
' Create new group level on OrderDate field.
varGroupLevel = CreateGroupLevel("OrderReport", "OrderDate", _
True, True)
' Set height of header/footer sections.
Reports!OrderReport.Section(acGroupLevel1Header).Height = 400
Reports!OrderReport.Section(acGroupLevel1Footer).Height = 400
End Sub
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.