Cancel printing if the report has more than one page

  • Thread starter Thread starter rsocol
  • Start date Start date
R

rsocol

I want to print a report only if it fits on one page. If it has more
than one page, I want to display a msgbox and cancel the printing of
the report.

My plan was to make a report footer and a page footer in the report; if
the page footer's print event appears before the report footer's print
event, then I want to cancel the printing of the entire report. If I
use the Cancel parameter of the Print event, Access only cancels
printing for that section. How can I cancel the printing of the entire
report ?

The detail section has some controls that can grow, so I cannot rely on
a "standard" number of details that fit on one page (if all my details
would have a fixed height, I could have checked the number of details
that will be printed in the Report_Open event and cancel it here... but
I have details that have variable heights).

I'm using Access XP (with ADP-s).

Razvan
 
Razvan,
How many records will fit on the first page. Let's say it's 20 records
for example.
When the user asks for the report, why not just do a DCount against the
table... using the criteria at the time, and if the DCount is over 20...
just exit the sub.
hth
Al Camp
 
I've already wrote that I have some controls in the Detail section that
have the CanGrow property set to True. Because of this, sometimes 20
records fit on a page, sometimes only 5.

Razvan
 
I want to print a report only if it fits on one page. If it has more
than one page, I want to display a msgbox and cancel the printing of
the report.

My plan was to make a report footer and a page footer in the report; if
the page footer's print event appears before the report footer's print
event, then I want to cancel the printing of the entire report. If I
use the Cancel parameter of the Print event, Access only cancels
printing for that section. How can I cancel the printing of the entire
report ?

The detail section has some controls that can grow, so I cannot rely on
a "standard" number of details that fit on one page (if all my details
would have a fixed height, I could have checked the number of details
that will be printed in the Report_Open event and cancel it here... but
I have details that have variable heights).

I'm using Access XP (with ADP-s).

Razvan

As far as I know you cannot cancel the report entirely based upon your
criteria.
The best I can offer you is for you to place the following code in
EACH section of the report:

If Me.[Pages] > 1 Then
Cancel = True
End If

You will get one blank sheet of paper.
If you wish a message also, you can add a MsgBox to the Report HEADER
Format event only:

If Me.[Pages] > 1 Then
MsgBox "Report has more than one page."
Cancel = True
End If
 
My mistake... I was reading a bit too fast.
Looks as though FredG has a work-around for you, so I hope you're all set
with that. Fred knows his stuff...

I would also try using the PageFooter Format or Print Event to Cancel=True.

Al Camp
 
Back
Top