Skip to Content
0
Former Member
Jul 24, 2009 at 02:57 PM

Continuous Numbering Across All Reports in Document

29 Views

I am trying to number all the pages in my document, which contains five reports. I need the reports to be numbered so that when the document is converted to pdf, the numbers are sequential throughout the entire document. I am using this VBA code in order to set the page numbers:

Private Sub RecountPages()
    On Error Resume Next
    Dim i As Integer
    Dim numPages As Integer
    numPages = 0
    
    For i = 1 To Me.Reports.Count
        Dim rep As Report
        Set rep = Me.Reports(i)
        Me.DocumentVariables("Page(" & i & ")").Formula = "=""Page: "" & FormatNumber(Page() + " & numPages & ", ""0"") & "" of """
        numPages = numPages + rep.NumberOfPages
    Next
    
    Me.DocumentVariables("AllPages").Formula = "=FormatNumber(" & numPages & ", ""0"")"
End Sub

I have document variables set up as <Page(1)>, etc. to display in each report and <AllPages> to display the total number of pages. Each page displays something like this: Page 1 of 18. This code works perfectly in Desktop Intelligence, but when I export this document and try to run it in InfoView, this line causes an error:

numPages = numPages + rep.NumberOfPages

I have determined that it is the property NumberOfPages that causes the error. Is there any way to work around this error or is there an alternative method of doing this?