Print specific report

krzysiekk

Registered User.
Local time
Today, 03:33
Joined
Dec 2, 2009
Messages
74
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..
 
Something like this:
Code:
    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
    Next
All untested/uncompiled code :)
 
Not working showing error, error saying is second report not existing, a check that and is not possible.
 
What is the exact error message?

What line does it highlight when you click DEBUG?
 
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
 
Here's the revised version:
Code:
    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
    Next
Still 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]
 
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.
 
thanks working fine problem was with source I add =[Page] but should be =[Pages]

Thanks
 

Users who are viewing this thread

Back
Top Bottom