Peter said:
Has anyone been able to produce a table of contents for a report in Access
2007; I have had no luck with the code at
http://support.microsoft.com/?id=210269.
Tony --
I am using my own database -- not Northwind.
Under the Macro tab, I created a module (named mod Table of Contents) with
the following code:
Option Explicit
Dim db As Database
Dim toctable As Recordset
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
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
When I try to run the report, I get the following error: "Microsoft Office
Access can't find the object 'InitToc().' "
-- Peter