Code:
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
If cmb_Type = 4 Then 'If the entry is of type 4, it is a header and should therefore be listed in the table of content
If CharCount(Me.tb_SectionNumber, ".") < 4 Then
rsTOC.FindFirst "ID=" & Me.tb_ID 'rsTOC is a table recordset. So, when adding entries to rsTOC, it is added to a table. All entries have the unique field ID
If rsTOC.NoMatch Then 'If, for some reason, the entry is already in the ToC, skip it.
m_TOCUpdated = True
rsTOC.AddNew
'Adding the entry to the ToC table (rsTOC)
rsTOC!ID = Me.tb_ID
rsTOC![SectionNumber] = Me.tb_SectionNumber
rsTOC![Text] = Me.tb_Text
rsTOC![Page] = Page
rsTOC.Update
Else
If rsTOC!Page <> Page Then
m_TOCUpdated = True
rsTOC.Edit
rsTOC![Page] = Page
rsTOC.Update
End If
End If
End If
End If
End Sub
This is the code inside Detail_Print. However, I doubt this is relevant, as, when the issue occurs, it never enters the Detail_Print at all.
The randomness of the problem is what annoys me the most. Using exactly the same content, Detail_Print is sometimes executed, sometimes not. As I stated in my original post; it is either executed for all entries (leading to a successful generation of the table of content) or for no entries at all (leading to a missing table of content).