Article ID: 131588
Article Last Modified on 1/19/2007
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
Indexed: No
NOTE: Make sure the Description field is the same data type as the
field on your report that you will use as a table of content heading.
Option Explicit
Dim db As Database
Dim toctable As Recordset
In Microsoft Access 1.x:
Option Explicit
Dim db As Database
Dim toctable As Table
Function InitToc ()
' Called from the OnOpen property of the report.
' Opens the database and the table for the report.
Dim qd As QueryDef
Set db = CurrentDb()
' Delete all previous entries in Table of Contents table.
Set qd = db.CreateQueryDef _
("", "Delete * From [Table of Contents]")
qd.Execute
qd.Close
' Open the table.
Set toctable = db.OpenRecordset("Table Of Contents", _
DB_Open_table)
toctable.index = "Description"
End Function
In Microsoft Access 1.x:
Function InitToc ()
' Called from the OnOpen property of the report.
' Opens the database and the table for the report.
Dim qd As QueryDef
Set db = CurrentDB()
' Delete all previous entries in the Table of Contents table.
Set qd = db.CreateQueryDef("Delete TOC Entries", "Delete * _
From [Table of Contents]")
qd.Execute
qd.Close
' Open the table.
Set toctable = db.OpenTable("Table Of Contents")
toctable.index = "Description"
Exit Function
End Function
In all versions:
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.AddNew
toctable!description = tocentry
toctable![page number] = Rpt.page
toctable.Update
End If
End Function
=InitToc()
=UpdateToc([CategoryName],Report)
NOTE: In version 2.0 or earlier, type a space in Category Name.
Keywords: kbhowto kbprogramming kbusage KB131588