Alison Balteramp;#039;s Mastering Microsoft Office Access 1002003 [Electronic resources]

Alison Balter

نسخه متنی -صفحه : 544/ 172
نمايش فراداده

Programmatically Manipulating Report Sections

Not only can you create and manipulate report sections at design time, you also can do so at runtime. You must first open the report in Design view. You use the DoCmd object to add a report header and footer or a page header and footer. The code appears in Listing 10.11.

Listing 10.11 Using the DoCmd Object to Programmatically Add Sections to Reports at Runtime
Private Sub cmdAddHeadersFooters_Click() 'Open rptAny in Design view DoCmd.OpenReport "rptAny", acViewDesign 'Add a report header and footer DoCmd.RunCommand acCmdReportHdrFtr 'Add a page header and footer DoCmd.RunCommand acCmdPageHdrFtr End Sub

You can also add section headers and footers. The code in Listing 10.12 illustrates the process. It is found in frmReportSections on the sample code CD.

Listing 10.12 Adding Sections to Reports at Runtime
Private Sub cmdAddSections_Click() Dim boolSuccess As Boolean 'Use CreateGroupLevel function to create a grouping 'based on the City field in the report rptAny boolSuccess = CreateGroupLevel("rptAny", "City", True, True) End Sub

Note that the CreateGroupLevel function receives four parameters. The first is the name of the report you want to affect. The second is an expression designating the expression on which the grouping is based. The third parameter allows you to specify whether you want the group to have a group header, and the final parameter lets you designate whether you want to include a group footer.