Question How to print only page 1 of a 2 page report (1 Viewer)

ghudson

Registered User.
Local time
Today, 08:14
Joined
Jun 8, 2002
Messages
6,195
Is it possible to print only page one of a two page report? I have a report that I want both pages to be printed for one instance when I send the report via DoCmd.sendobject acReport or open it via DoCmd.OpenReport but for another instance I only want page one to be printed. I have searched around but found nothing. Anyone have any VBA suggestions?

Thanks in advance for your help!
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:14
Joined
Sep 12, 2006
Messages
15,658
can you not open in preview mode - then let the user decide what he wants.
 

ghudson

Registered User.
Local time
Today, 08:14
Joined
Jun 8, 2002
Messages
6,195
When using the below code I am gettting the error "This action cannot be carried out while processing a form or report event".

Code:
DoCmd.PrintOut acPages, 1, 1

What event of the report should this code be in?
 
Last edited:

ghudson

Registered User.
Local time
Today, 08:14
Joined
Jun 8, 2002
Messages
6,195
can you not open in preview mode - then let the user decide what he wants.

No I cannot. The report is being either emailed or saved to the network. All the user does is click a button and choose the location number to filter the report on. I am trying to avoid making two copies of the report, one to print both pages and the other to only print page 1.
 

boblarson

Smeghead
Local time
Today, 05:14
Joined
Jan 12, 2001
Messages
32,059
can you not open in preview mode - then let the user decide what he wants.

In some circumstances you may want to print it directly without user intervention. I give you an example. I built a POS system for a retail establishment a few years ago. They had a form which had the purchases there where they had entered everything. They just had to click the RECEIPT button to print a receipt. They didn't want, or need to preview it, they just needed it to print two copies which I had it do.

So there are times where you need a print but do not want user intervention. And I think this is one of those cases. So, the PrintOut command should work as you open the report and then use printout but I think you can open the report hidden so you don't have to see it in order to print. I could be wrong there but that's my thought.
 

boblarson

Smeghead
Local time
Today, 05:14
Joined
Jan 12, 2001
Messages
32,059
When using the below code I am gettting the error "This action cannot be carried out while processing a form or report event".

Code:
DoCmd.PrintOut acPages, 2, 2

What event of the report should this code be in?

It doesn't go in an event of the report. You use it after opening it in acViewPreview but with the window mode of acHidden.
 

ghudson

Registered User.
Local time
Today, 08:14
Joined
Jun 8, 2002
Messages
6,195
It doesn't go in an event of the report. You use it after opening it in acViewPreview but with the window mode of acHidden.

Well this code does allow me to externally call it and only print page 1 of the report and the code within the report is working so the user can key which location they want to report filtered on. But I wish I could put the print code within the report so that I could use an IF to determine if I want only page 1 printed or print all pages of the report based on which form is opened when the report is called.

Code:
DoCmd.SelectObject acReport, "MyReport", True
DoCmd.PrintOut acPages, 1, 1

Thanks for your help!
 

Users who are viewing this thread

Top Bottom