This article describes how you can create a table of contents or an index for a
: This article describes a technique that is demonstrated in the sample
For additional information about how to obtain this sample file, click the article number below
to view the article in the Microsoft Knowledge Base:
ACC2000: Microsoft Access 2000 Sample Reports Available in Download Center
Microsoft Access does not have a table-of-contents feature or an index
feature for reports. However, you can use a table to store descriptions
and page numbers, and then create a report that is based on that table to use as a
Table of Contents report. You can use the same method to create an index.
To create a report that generates a table of contents, follow these steps.CAUTION
: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.
- Open the sample database Northwind.mdb.
- Create the following table, and then save it as Table Of Contents:
NOTE: Make sure the Description field is the same data type as the field that is on
your report that you use as a table-of-contents heading.
Table: Table Of Contents
Field Name: Description
Data Type: Text
Field Size: 15
Indexed: Yes (No Duplicates)
Field Name: Page Number
Data Type: Number
Field Size: Long Integer
- Create a module, and then type the following lines in the "Declarations" section:
Dim db As DAO.Database
Dim TocTable As DAO.Recordset
Dim intPageCounter As Integer
- Create the following procedure:
'Called from the OnOpen property of the report.
'Opens the database and the table for the report.
Dim qd As DAO.QueryDef
Set db = CurrentDb()
'Resets the page number back to 1
intPageCounter = 1
'Delete all previous entries in Table of Contents table.
Set qd = db.CreateQueryDef("", "Delete * From [Table of Contents]")
'Open the table.
Set TocTable = db.OpenRecordset("Table Of Contents", dbOpenTable)
TocTable.Index = "Description"
Function UpdateToc(TocEntry As String, Rpt As Report)
'Call from the OnPrint property of the section containing
'the Table Of Contents Description field.
'Updates the Table Of Contents table.
TocTable.Seek "=", TocEntry
If TocTable.NoMatch Then
TocTable!Description = TocEntry
TocTable![page number] = intPageCounter
intPageCounter = intPageCounter + 1
- Open the Products by Category report in Design view, and then set the OnOpen property of the report as follows:
- Select the CategoryName header, and then set the OnPrint property of the header as follows:
- Select the Page Footer, and then set the OnPrint property of the page footer as follows:NOTE: When you preview or you print the report, the Table Of Contents table is updated. The Table Of Contents table records the page on which each new category begins.
When you preview the report, page through all of the pages of the
report to make sure that the Print event is triggered for all records.
- Create another report that is based on the Table Of Contents table to print the table of contents.
To print the table of contents, print the Products by Category report first, and then print the Table Of Contents report.
Article ID: 210269 - Last Review: October 11, 2006 - Revision: 1.3
- Microsoft Access 2000 Standard Edition
|kbhowto kbprogramming kbusage KB210269|