How to print two copies of each page of the report

You might try opening the report in "Preview" mode. Then set a global variable to the number of pages in your report.

Set up the global variable in a module in the declarations section

Code:
Option Compare Database
Option Explicit
Public gblPagesInReport As Integer

You can then set the global variable value in the reports On Page event

Code:
gblPagesInReport = Pages


Then use the "PrintOut" method in the same code that opens your report in preview mode, to form a loop to print out each page of your report TWICE.

Code:
DoCmd.OpenReport "yourreportname", acViewPreview
 
For T = 1 to glbPagesInReport
     DoCmd.PrintOut acPages, T, T
     DoCmd.PrintOut acPages, T, T
Next T

I have not tested this but programatically it should work.


Richasrd
 
Aman,

In my previous post, I suggested using the PrintOut command to achieve printing x copies of each page of a report, then continuing to next page. I had not had a chance to test my programming. Today I tested the code at work and it did exactly what you are trying to achieve. It printed x copies of each page of the report before proceeding to the next page.

This is the actual code I came up with.

I placed a variable in the declarations section of the module and named it glbReportPages.

Code:
[FONT=Times New Roman][SIZE=3]Option Compare Database[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Option Explicit[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]Public glbReportPages As Integer[/SIZE][/FONT]

I created a text control on the report was set to the variable [Pages] or I would get 0 for the pages. I hid the control, but most reports do show the page number and number of pages. Exam: ="Page " & [Page] & " of " & [Pages]

Then I entered the following code in the reports Report properties On Page event.

Code:
[FONT=Times New Roman][SIZE=3]Private Sub Report_Page()[/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]  glbReportPages = Pages[/FONT][/SIZE]
[FONT=Times New Roman][SIZE=3]End Sub[/SIZE][/FONT]


On the form designed to print the report I created a text control called txtCopies and set it’s default value to 2 to keep with the 2 copies you require. And by doing so I could change the number of copies that would be printed before printing them.

I then created a command button called cmdPrint and placed the following code in the cmdPrint controls’ On Click event.

Code:
[FONT=Times New Roman][SIZE=3]Private Sub cmdPrint_Click()[/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3]On Error GoTo Err_Command0_Click[/SIZE][/FONT]
 
[SIZE=3][FONT=Times New Roman]  Dim T As Integer[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]  Dim intPages As Integer[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]  Dim stDocName As String[/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman]  stDocName = "ReportProducts"[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]  DoCmd.OpenReport stDocName, acPreview[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]  intPages = glbReportPages[/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman]  For T = 1 To intPages[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]      DoCmd.PrintOut acPages, T, T, acDraft, txtCopies, No[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]  Next T[/FONT][/SIZE]
 
[SIZE=3][FONT=Times New Roman]  DoCmd.Close acReport, "ReportProducts"[/FONT][/SIZE]
 
[FONT=Times New Roman][SIZE=3]Exit_Command0_Click:[/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]  Exit Sub[/FONT][/SIZE]
 
[FONT=Times New Roman][SIZE=3]Err_Command0_Click:[/SIZE][/FONT]
[SIZE=3][FONT=Times New Roman]  MsgBox Err.Description[/FONT][/SIZE]
[SIZE=3][FONT=Times New Roman]  Resume Exit_Command0_Click[/FONT][/SIZE]
 
[FONT=Times New Roman][SIZE=3]End Sub[/SIZE][/FONT]

Upon clicking the command button the report opened in preview mode. The code then ran to print x copies, the value in the txtCopies control, of each page, getting the number of pages from the glbReportPage variable and then closed the report.

I used the glbReportPage variable so a report containing any of number of pages could be printed without knowing the exact number of pages in the report.

I am using Access 2000 so I can’t guarantee that it will work with later versions of access, but it did work perfectly when tested.

Hope this helps

Richard

P.S. The report MUST be open in preview so you will print copies of the report and not the form that is used to pring the report.
 
Last edited:
Did you know that when you individually print page 48 of a report, that Access has to go through the previous 47 pages from 1 through to 47 before it knows what page 48 should look like.

And when you print page 49 individually, it has to go through the previous 48 pages from 1 through to 48 (again) before it knows what page 49 looks like.

And when you print page 50 individually, it has to go through the previous 49 pages from 1 through to 49 (again) before it knows what page 50 looks like.

Your report is going to take forever to print if you start to get larger outputs, or your query is complex with subreports.

Obviously my method was far too simple (not requiring any VBA), and you needed something more complex to get your teeth into :rolleyes: .....but hey if your solution works......:)
 
Hi Endre

I tried your method and I know its very simple solution to my problem but its giving me some problem. Sometimes it doesn't print page header and sometimes it displays page header at the footer section. I don't know why its happening.
In the query section,there are two tables:tbldocumentrequest and t_1.t_1 as you suggeted has only one field and its purpose is to print two copies of each page. But during printing it misses page header and sometimes page header appears at page footer section.
If I use the code I had written at very first post then everything works fine except the copies don't collate together. Can you tell me how to count the total number of pages in a report and then I can use for loop to print each page twice. I can't send you the attached file as its resticted in my company.

Thanks
Aman
 
Hi Aman - I have checked rapsr59's code (Post #22) and it works just fine for me. The "Last Page Number" you are looking for is:

Pages

or also when referencing the report

Me.Pages

e.g.
"Now Viewing Page " & Me.Page & " Of " & Me.Pages & " Page(s)"

Please note that when you use Me.Pages, Access has to run through the entire report as though it were printing it in order to calculate the value for Me.Pages so you should minimise time and try to run this once only.

His code sets the global variable for use to Pages

The other thing you can do is set a control e.g. ctl_LastPageNo in your report to [Pages] and then refer to this value e.g. to amend raspr59's code:

intPages = Application.Reports("Report1").Controls("ctl_LastPageNo").Value
For T = 1 To intPages
DoCmd.PrintOut acPages, T, T, acDraft, txtCopies, False
Next T
etc..


Now you don't need a global variable as you are picking the value up from your control in your report. BUT, each time you print your report page by page it has to run to the last page each time to get the number of pages so it can be shown. So I suggest you don't use this method - though it may make you more comfortable.
 
FYI...
Doing a quick search in the VBA Editor for "Collate" brought up the PrintOut Action. Based off of the Help file, there is an option there to print specific pages, Number of Copies as well as to Collate. Might be worth checking out. :)

I've never used the PrintOut Action, so I dont know exactly how to use it...but I'm sure if you play around with it you can figure it out
 

Users who are viewing this thread

Back
Top Bottom