Hayley Baxter
Registered User.
- Local time
- Today, 15:16
- Joined
- Dec 11, 2001
- Messages
- 1,607
I am trying to run a table of contents for my report but as I have never attempted this before I am having some problems. I have set up a table to include the fields for my table of contents and added a module to run this. I don't get any error messages the table of contents just doesn't appear.
Here is the code:
Option Explicit
Option Compare Database
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
Has anyone used this before or can suggest where I might be going wrong?
Thanks
Hay
Here is the code:
Option Explicit
Option Compare Database
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
Has anyone used this before or can suggest where I might be going wrong?
Thanks
Hay