I have a very bizarre prob. I have some code to create a table of contents/index for a report which has "chapters" which can be added or dropped depending on whether we choose to stock something or not. And I'm getting the strangest issue. The very first "chapter" starts fine on Page 1. But the next item we sell (Chap 2), then starts on Page 3, instead of Page 2. Here's what's strange. Every other item is then one page off. Any ideas? Below is my code.
Code:
Option Compare Database
Dim db As Database
Dim TocTable As 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 QueryDef
Set db = CurrentDb()
'Resets the page number back to 1
intPageCounter = 1
'Delete all previous entries in Table of Contents table.
Set qd = db.CreateQueryDef("", "Delete * From [Index for Pricebook]")
qd.Execute
qd.Close
'Open the table.
Set TocTable = db.OpenRecordset("Index for Pricebook", dbOpenTable)
TocTable.Index = "Series"
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!Series = TocEntry
TocTable![Page Number] = intPageCounter
TocTable.Update
End If
End Function
Function UpdatePageNumber()
intPageCounter = intPageCounter + 1
End Function
The InitToc fx is called upon the opening of the pricebook, the UpdateToc fx is called upon printing. There's something in here where I think I'm calling the functions incorrectly, but I'm not sure quite what the error is.