View Full Version : Print specific report


krzysiekk
08-03-2010, 07:44 AM
Hi

I got 4 reports, - (rep1, rep2, rep3, rep4) each 5 pages

its possible to print report like that:

rep1 - page1
rep2 - page1
rep3 - page1
rep4 - page1
rep1 - page2
rep2 - page2
rep3 - page2
rep4 - page2
etc....

please help me..

vbaInet
08-03-2010, 11:33 PM
Something like this:
Dim rpt As Report, rptNames$(), i%, j%, maxPages%

' Put the four report names in an array
ReDim rptNames(1 To 4)
rptNames(1) = "report 1"
rptNames(2) = "report 2"
rptNames(3) = "report 3"
rptNames(4) = "report 4"

' Open all four reports and get the max number of pages
For i = LBound(rptNames) To UBound(rptNames)
DoCmd.OpenReport rptNames(i)
DoEvents

' Get max number of pages here
Set rpt = Reports(rptNames(i)).Report
If rpt.Pages > maxPages Then
maxPages = rpt.Pages
End If
Next

' Loop through reports and print
For i = 1 To maxPages
For j = LBound(rptNames) To UBound(rptNames)
Set rpt = Reports(rptNames(j)).Report
If rpt.Pages <= maxPages Then
DoCmd.SelectObject acReport, rpt.Name, False
DoCmd.PrintOut acPages, i, i
End If
Next
NextAll untested/uncompiled code :)

krzysiekk
08-04-2010, 08:45 AM
Not working showing error, error saying is second report not existing, a check that and is not possible.

vbaInet
08-04-2010, 08:54 AM
What is the exact error message?

What line does it highlight when you click DEBUG?

krzysiekk
08-04-2010, 02:01 PM
When I press button showing error:
The report name driploss you entred is misspelled or refers to a report that isn't open or doesn't expist when i debug line:
Set rpt = Reports(rptNames(i)).Report

vbaInet
08-04-2010, 05:36 PM
Here's the revised version:
Dim rpt As Report, rptNames$(), i%, j%, maxPages%

' Put the four report names in an array
ReDim rptNames(1 To 4)
rptNames(1) = "report 1"
rptNames(2) = "report 2"
rptNames(3) = "report 3"
rptNames(4) = "report 4"

' Open all four reports and get the max number of pages
For i = LBound(rptNames) To UBound(rptNames)
DoCmd.OpenReport rptNames(i), acViewPreview
DoEvents

DoCmd.SelectObject acReport, rptNames(i), False

' Get max number of pages here
Set rpt = Reports(rptNames(i)).Report
If rpt.Pages > maxPages Then
maxPages = rpt.Pages
End If
Next

' Loop through reports and print
For i = 1 To maxPages
For j = LBound(rptNames) To UBound(rptNames)
Set rpt = Reports(rptNames(j)).Report
If i <= rpt.Pages Then
DoCmd.SelectObject acReport, rpt.Name, False
DoCmd.PrintOut acPages, i, i
End If
Next
Next

' Close the reports
For i = LBound(rptNames) To UBound(rptNames)
DoCmd.Close acReport, rptNames(i), acSaveNo
NextStill untested and uncompiled :)

By the way, you MUST include a page count at the Page Footer section of your reports for this to work. So put a textbox on the Page Footer section of each report and put this in the control source =[Page]

krzysiekk
08-05-2010, 07:25 AM
Hi and looks ok. No errors but just no printing...

vbaInet
08-05-2010, 07:27 AM
Msgbox Me.Pages to see how many pages each one has. If you don't have a textbox that does the page count it won't work.

krzysiekk
08-05-2010, 08:22 AM
thanks working fine problem was with source I add =[Page] but should be =[Pages]

Thanks

vbaInet
08-05-2010, 08:23 AM
Glad that's working for you.