Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in figuring out programming table of contents for a report

Status
Not open for further replies.

inso18

Technical User
Dec 30, 2006
147
IL
Hello all!

For my report that has 'ShopName' grouping which appears in detail section I'm trying to combine a table of contents tabular one-page subform that would be located at the forum header section. Searching through Microsoft help I have found this code to be used for creating a table of contents:


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

New Module:
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

Report's OnOpen Event:
=InitToc()
On the report's detail OnPrint event:
=UpdateToc([ShopName],Report)


There are 2 problems with this code:
1. I have to open the report, and go through all its pages in order to have the table of contents to be combined
correctly.
2. I can't view the table of contents that is on the report's header section when I open the report because it isn't combined yet! The table is deleted each time I open the report.

Can you assist me in combining a code that will display the table of contents on the forum's header section in a tabular subform, preferably without the need to go through all the reports pages in order to have it created?

Much thanks,
inso.
 
A typo: in the beginning of my I wrote form and subform, but I meant report and subreport of course.
 
A typo: in the beginning of my post I wrote form and subform, but I meant report and subreport, of course.
 
this is more or less the way. You can open the TOC report, have it open the body of the report, then close/reopen the body of the report just using the TOC table created earlier. Even this has some 'issues', as the TOC may record incorrect page numbers if a report section has a 'rolll back' event - which Ms. fails to mention or account for in their code.



MichaelRed


 
Is there a way to automatically browse all the report for recording the TOC in order to save this task from a human?
 
see the earlier post. I did NOT mean that a 'person' needed to do it. Event(s) in the TOC routine can easily handle the opening of the body of the report, searching the content for and adding the Pg # info to a basic table to be use by the main / body report for the TOC.

several tricks/traps along the way, but the entire op CAN be done with a 'single' UI function.




MichaelRed


 
Thanks Michael.

Can you suggest me anything to read in order to understand how to properly conduct such an operation?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top