Discrepancy between Print Preview and Actual Printout

G

Guest

Hello all,

I've the following code running in the Detail Format section of my report.
It'll insert a page break when the [Day] field increments by 1. When i scroll
through the pages of my report the first time (in Print Preview), the code
runs and page breaks are inserted properly. Then i pressed Print and the
actual printout of my report has no page breaks in them!!! Please help! I
appreciate any inputs, thanks in advance!

Here is the code:

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

Static intA As Integer
Dim intB As Integer

intB = Me![Day] + 1

If intB = 3 And intA = 0 Then
Me![NewDay].Visible = True
intA = intA + 1
ElseIf intB = 4 And intA = 1 Then
Me![NewDay].Visible = True
intA = intA + 1
ElseIf intB = 5 And intA = 2 Then
Me![NewDay].Visible = True
intA = intA + 1
ElseIf intB = 6 And intA = 3 Then
Me![NewDay].Visible = True
intA = intA + 1
Else
Me![NewDay].Visible = False
End If

End Sub
 
A

Allen Browne

All the events run again when the report is printed after preview. That
means you need to reset intA before the print run to get the results you
wish.

Delete:
Static intA As Integer.
Instead, declare intA in the General Declarations section (top of the
report's module, with the Option statements):
Private intA As Integer
It is now available to all the procedures in the module, and has a lifetime
as long as the module.

Reset the variable in the Format event of the Report Header section:
intA = 0
If you do not have a Report Header section, it's on the View menu. You can
make it zero-height if you don't want anything printed.

BTW, the code is likely to give wrong results if the user does not print all
the pages of the report. In that case, the code may not run for the missed
pages, so the results are not what you intend.
 
G

Guest

AWESOME!!! Clear and concise, with details sufficient for the novice!!!
Thanks a lot Allen, appreciate it very much!!!

Regarding the likelyhood for the code to produce the wrong results when user
only prints a few pages, i still haven't work out how to resolve that yet and
will continue trying. Thanks again!
 

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