On Sun, 31 Jul 2005 20:31:49 +1000, Robin Chapple wrote:
Robin,
See my comments marked with *** in line below.
*** snipped ***
I have returned to this project following some domestic trauma.
The first report has 30 pages. It correctly sets intLastPage to 30 and
puts 31 into the contents table for the first page number of the next
report.
I have now added the code to the second report which has just three
pages.
The first page in page number 31 as expected,
The second page is page 62 and
The third page is page 93
which looks like the second report second page number is second report
first page plus the "intLastPage" and so on.
Here is the VBA:
Option Compare Database
Option Explicit
Dim intPageCount As Integer
*** You have combined 2 different posts from 2 different threads in 2
different news groups.
intPageCount is not needed as it serves the same purpose as
intLastPage. See *** below
Dim intLastPage As Integer
Private Sub PageHeader_Format(Cancel As Integer, FormatCount As
Integer)
[Page] = [Page] + intLastPage
*** This is not the correct event for this.
It must go in the Report Header Format event, not the Page Header.
You want to increment just the first page of each report by 30, not
each page by 30. The report itself takes care of incrementing the
second, third, etc. pages.
The Page Header event is run on each page, therefore you were getting
30 added to each page.
The code in the Report Header is run just once per report.
The first page of the second report is 31 (1+30), the next page is 32
(31 + 1), the third page is 33 (32 + 1), etc., which is what you want.
End Sub
Private Sub Report_Open(Cancel As Integer)
DoCmd.Maximize
intLastPage = DLookup("intPageNumber", "tblPage")
*** This is OK.
End Sub
Private Sub ReportFooter_Format(Cancel As Integer, FormatCount As
Integer)
intPageCount = [Page]
CurrentDb.Execute "Update tblcontents Set tblContents.District
= " & [intPageCount] + 1 & ";", dbFailOnError
*** This is OK, but you can combine this code with the code in the
Report Footer Print event.
End Sub
Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As
Integer)
DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblPage Set tblPage.intPageNumber = " &
[Page] & ";"
DoCmd.SetWarnings True
*** This is OK, but you can include the above Format event code with
this.
End Sub
===============
Thanks,
Robin Chapple
Here is what the entire code will look like.
I've changed the DoCmd.RunSQL to CurrentDb.Execute statements.
Using the Execute statement instead of RunSQL there is no need for
SetWarnings False and SetWarnings True.
Watch out for improper e-mail line wrapping on the longer lines.
Option Compare Database
Option Explicit
Dim intLastPage As Integer
===========
Private Sub Report_Open(Cancel As Integer)
' On the FIRST report that is run
' re-set the table field to Zero.
CurrentDb.Execute "Update tblPage Set tblPage.intPageNumber = 0;",>dbFailOnError
' On ALL the reports, including the first one
DoCmd.Maximize
intLastPage = DLookup("intPageNumber", "tblPage")
End Sub
==============
Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As
Integer)
[Page] = [Page] + intLastPage
End Sub
=============
Private Sub ReportFooter_Print(Cancel As Integer, PrintCount As
Integer)
' I've combined your Report Footer Format and Print events here.
' Your previous intPageNumber is not needed here.
' We'll use [Page] instead.
CurrentDb.Execute. "Update tblPage Set tblPage.intPageNumber = " &
[Page] & ";", dbFailOnError
CurrentDb.Execute "Update tblcontents Set tblContents.District = " & [Page] + 1 & ";", dbFailOnError
End Sub
================
I hope this explains why you were getting such large page numbers, and
gets you on-track again.