F
F1stman
Hello,
I am having some issues with code to create a table of contents table for
later referrencing. I have following instructions from a help page located at
http://support.microsoft.com/kb/q131588/ to the best of my abilities. Please
see the following code modified from this example. It is saved in the
TableofContents Module.
Option Compare Database
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 [TableofContents]")
qd.Execute
qd.Close
' Open the table.
Set toctable = db.OpenRecordset("TableOfContents", 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
InitToc() is entered in the OnOpen event of the report (Called "CIP3" and
UpdateToc([Proj_Title],[Report]) is entered in the OnPrint event of the
header. However, I am running into the following errors:
When I open the report, I get the message "Invalid Operation" and the debug
takes me to the "set toctable" line (third from bottom in first part or
InitToc() part of code).
At one point I could avoid this but got a "type mismatch" error for the
OnPrint or UpdateToc() event.
Any help is appreciated. I am desperate at this point and don't really
understand the code I am using.
Thanks, Adam Kemp
I am having some issues with code to create a table of contents table for
later referrencing. I have following instructions from a help page located at
http://support.microsoft.com/kb/q131588/ to the best of my abilities. Please
see the following code modified from this example. It is saved in the
TableofContents Module.
Option Compare Database
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 [TableofContents]")
qd.Execute
qd.Close
' Open the table.
Set toctable = db.OpenRecordset("TableOfContents", 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
InitToc() is entered in the OnOpen event of the report (Called "CIP3" and
UpdateToc([Proj_Title],[Report]) is entered in the OnPrint event of the
header. However, I am running into the following errors:
When I open the report, I get the message "Invalid Operation" and the debug
takes me to the "set toctable" line (third from bottom in first part or
InitToc() part of code).
At one point I could avoid this but got a "type mismatch" error for the
OnPrint or UpdateToc() event.
Any help is appreciated. I am desperate at this point and don't really
understand the code I am using.
Thanks, Adam Kemp