Page numbering

H

hughess7

Hi all

I have some code I found on the forum for creating Page numbering to run
sequentially over two different reports ie report 1 starts at page 1 and
report 2 starts at the end of report 1 + 1. This works when I code reports to
print, report 2 starts at Page 6 as desired. But when I code to preview the
reports only (how they normally work) the page numbering is not correct in
that report 2 starts at page 2 (instead of 6).

Do I need something in between the docmd.openreport preview commands calling
the two reports, maybe some sort of time delay to wait for report 1 to finish
processing? Or is it because I haven't moved through the pages when its
previewed so it hasn't triggered/looped through its formatting section fully?

Thanks for any help...

Code on each report is:

Dim intLastPage As Integer

Private Sub PageFooterSection_Print(Cancel As Integer, PrintCount As Integer)

DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblPage Set tblPage.intPagenumber=" & [Page] & ";"
DoCmd.SetWarnings True

End Sub

Private Sub Report_Open(Cancel As Integer)

' only on report 1 reset PageNo to start at 0
DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblPage Set tblPage.intPagenumber=0;"
DoCmd.SetWarnings True

intLastPage = DLookup("[intPageNumber]", "[tblPage]")

End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)

[Page] = [Page] + intLastPage

End Sub
 
S

Sue

Hi Ken

Excellent thanks!!!

It didn't work with the openarg conditions but I always want report 1 to
open anyway with report 2, so I removed the conditions and this works great
:). I assume I can't use 'Page 1 of x' on the reports, or can I use another
variable and add the Pages together???

Sue

KenSheridan via AccessMonster.com said:
You should be able to do this by opening the second report from within the
first report's module, and referencing the Pages property of the first
report
rather than its Page property. For this you'll need text box in the first
report's page footer which references the Pages property, e.g. with a
ControlSource =Pages, but this control can be hidden if necessary. The
page
number does not need to be stored in a table.

Then in the Print event procedure of the first report's report header
section
put:

If Me.OpenArgs = "Follow on" Then
DoCmd.OpenReport "Report2", _
View:=acViewPreview, _
OpenArgs:=(Me.Pages)
End If

and in the Format event procedure of the second report's report header
section put:

If Not IsNull(Me.OpenArgs) Then
Me.Page = Me.OpenArgs + 1
End If

The open the first report with:

DoCmd.OpenReport "Report1",View:=acViewPreview,OpenArgs:="Follow on"

By passing 'Follow on' as the OpenArgs property to the first report this
ensures that it only opens the second report and passes the number of
pages
to it if the first report has been opened in this way. Opening it without
passing the string would cause it to open on its own. If you want the
second
report to follow on from the first every time the first report is opened
then
you don't need to pass the string as the OpenArgs property of course; you
can
simply make the code in the first report's header's Print event procedure
unconditional.

Ken Sheridan
Stafford, England
Hi all

I have some code I found on the forum for creating Page numbering to run
sequentially over two different reports ie report 1 starts at page 1 and
report 2 starts at the end of report 1 + 1. This works when I code reports
to
print, report 2 starts at Page 6 as desired. But when I code to preview
the
reports only (how they normally work) the page numbering is not correct in
that report 2 starts at page 2 (instead of 6).

Do I need something in between the docmd.openreport preview commands
calling
the two reports, maybe some sort of time delay to wait for report 1 to
finish
processing? Or is it because I haven't moved through the pages when its
previewed so it hasn't triggered/looped through its formatting section
fully?

Thanks for any help...

Code on each report is:

Dim intLastPage As Integer

Private Sub PageFooterSection_Print(Cancel As Integer, PrintCount As
Integer)

DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblPage Set tblPage.intPagenumber=" & [Page] & ";"
DoCmd.SetWarnings True

End Sub

Private Sub Report_Open(Cancel As Integer)

' only on report 1 reset PageNo to start at 0
DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblPage Set tblPage.intPagenumber=0;"
DoCmd.SetWarnings True

intLastPage = DLookup("[intPageNumber]", "[tblPage]")

End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)

[Page] = [Page] + intLastPage

End Sub
 
S

Sue

Got this to work now I think by creating text boxes to store the Pages from
each report and then adding these together, thanks.

Sue said:
Hi Ken

Excellent thanks!!!

It didn't work with the openarg conditions but I always want report 1 to
open anyway with report 2, so I removed the conditions and this works
great :). I assume I can't use 'Page 1 of x' on the reports, or can I use
another variable and add the Pages together???

Sue

KenSheridan via AccessMonster.com said:
You should be able to do this by opening the second report from within
the
first report's module, and referencing the Pages property of the first
report
rather than its Page property. For this you'll need text box in the
first
report's page footer which references the Pages property, e.g. with a
ControlSource =Pages, but this control can be hidden if necessary. The
page
number does not need to be stored in a table.

Then in the Print event procedure of the first report's report header
section
put:

If Me.OpenArgs = "Follow on" Then
DoCmd.OpenReport "Report2", _
View:=acViewPreview, _
OpenArgs:=(Me.Pages)
End If

and in the Format event procedure of the second report's report header
section put:

If Not IsNull(Me.OpenArgs) Then
Me.Page = Me.OpenArgs + 1
End If

The open the first report with:

DoCmd.OpenReport "Report1",View:=acViewPreview,OpenArgs:="Follow on"

By passing 'Follow on' as the OpenArgs property to the first report this
ensures that it only opens the second report and passes the number of
pages
to it if the first report has been opened in this way. Opening it
without
passing the string would cause it to open on its own. If you want the
second
report to follow on from the first every time the first report is opened
then
you don't need to pass the string as the OpenArgs property of course; you
can
simply make the code in the first report's header's Print event procedure
unconditional.

Ken Sheridan
Stafford, England
Hi all

I have some code I found on the forum for creating Page numbering to run
sequentially over two different reports ie report 1 starts at page 1 and
report 2 starts at the end of report 1 + 1. This works when I code
reports to
print, report 2 starts at Page 6 as desired. But when I code to preview
the
reports only (how they normally work) the page numbering is not correct
in
that report 2 starts at page 2 (instead of 6).

Do I need something in between the docmd.openreport preview commands
calling
the two reports, maybe some sort of time delay to wait for report 1 to
finish
processing? Or is it because I haven't moved through the pages when its
previewed so it hasn't triggered/looped through its formatting section
fully?

Thanks for any help...

Code on each report is:

Dim intLastPage As Integer

Private Sub PageFooterSection_Print(Cancel As Integer, PrintCount As
Integer)

DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblPage Set tblPage.intPagenumber=" & [Page] & ";"
DoCmd.SetWarnings True

End Sub

Private Sub Report_Open(Cancel As Integer)

' only on report 1 reset PageNo to start at 0
DoCmd.SetWarnings False
DoCmd.RunSQL "Update tblPage Set tblPage.intPagenumber=0;"
DoCmd.SetWarnings True

intLastPage = DLookup("[intPageNumber]", "[tblPage]")

End Sub

Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As
Integer)

[Page] = [Page] + intLastPage

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top