I have a TOC but what now...

  • Thread starter Thread starter John Desselle
  • Start date Start date
J

John Desselle

Using Access2K and Windows2K...

I got a Table of Contents built for a report of mine using the
instructions from MS
http://support.microsoft.com/support/kb/articles/Q131/5/88.asp?PR=ACC.

But this is for my boss to be able to use and I KNOW she doesn't want
to either print the first report or view each page of the report
before the TOC will work correctly.

Is there any way to have the computer open the main report, scroll
through all the pages, "Formating Page..." then open the TOC in such
an order that my boss can send the entire thing, TOC first, to the
printer and have it stapled? (I can get the printer to staple, but
don't know how to get the report in the desired order.)

Thanks for any tips...(I'm not sure if I will get the responses via
email or not so please sent them to me at the below address)

John Desselle
Database/IT Administrator
Louisiana Trial Lawyers Association
442 Europe St., Baton Rouge, LA 70802
(800) 354-6267 or (225) 383-5554 - phone
(800) 380-6267 or (225) 387-1993 - fax
Direct line (225) 242-4828
email: (e-mail address removed)
web site: www.ltla.org
 
I found the answer I was looking. Just incase anyone besides has been
waiting on any reply to this...I thought I would share what I found.
If you put this code in the proper places on one report, it will open
with the TOC being the first page.

Here is a copy of the code that does all of this.
*****************************************************************************
Option Compare Database
Option Explicit

Dim db As DAO.Database
Dim TocTable As DAO.Recordset
Dim intPageCounter As Integer
*****************************************************************************
Function InitToc()
'Called from the OnOpen property of the report.
'Opens the database and the table for the report.
Dim qd As DAO.QueryDef

Set db = CurrentDb()

'Resets the page number back to 1
intPageCounter = 1
'Delete all previous entries in the 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", dbOpenTable)

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] = intPageCounter
TocTable.Update
End If
End Function
*****************************************************************************
Function UpdatePageNumber()
intPageCounter = intPageCounter + 1
End Function
 
I posted a follow up to this, but accidently pasted the wrong code.
Sorry about any confusion!

Here is the code that will make one report begin with a TOC:

Option Compare Database
Dim i As Integer
Dim myarray(2000)
Dim onlyonce As Integer
*****************************************************************************
Private Sub GroupHeader2_Format(Cancel As Integer, FormatCount As
Integer)
'This procedure fills the array, which will later assign the values to
the field
'on the report designated to "catch" the table of contents.
Dim j As Integer
'This for-next loop checks to make sure that duplicate entries do not
enter into
'the array, from moving between the pages. It also takes care of the
page
'numbering problem if the whole group will not fit on the same page.
It simply
'adds the correct entry for the page number into the array.

For j = 0 To i Step 2
If myarray(j) = (Reports![rpt01Area/CategoryListing]![Category])
Then
myarray(j + 1) = Reports![rpt01Area/CategoryListing]![pagenum]
GoTo skip_to_here
End If
Next j

'This simply fills the array
myarray(i) = Reports![rpt01Area/CategoryListing]![Category]
i = i + 1
myarray(i) = Reports![rpt01Area/CategoryListing]![pagenum]
i = i + 1
Exit Sub

'There is nothing to do, it was necessary to just skip adding an entry
to the array
skip_to_here:

End Sub
*****************************************************************************
Private Sub Report_Open(Cancel As Integer)
'Initialize the array "counter"
i = 0
'Initialize the variable, true: the table of contents still needs to
be built
onlyonce = -1
End Sub
*****************************************************************************
Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As
Integer)
'This procedure simply takes the full array and builds the table of
contents
'structure, so that it will display in a readable manner. Then
assigns the
'structure to the table of contents variable on the first page.

Dim k As Integer
Dim a As String

'This only builds the first page one time --- hence onlyonce
If onlyonce Then
a = ""
For k = 0 To i - 1
If (k Mod 2) = 0 Then
a = a & myarray(k) &
"............................................................"
Else
a = a & myarray(k) & Chr(13) & Chr(10) & Chr(10)

End If
Next k
Me![toc] = a 'Assign the structure to the field on the report
onlyonce = 0 'It was built once, no need to build it again

End If
End Sub
*****************************************************************************
 
Back
Top