Link to home
Start Free TrialLog in
Avatar of jrimmele
jrimmele

asked on

Make an object active for PrintOut Method

I have a report that is 6 pages long for each record in a query.  I want to be able to determine the number of records in the query, and then print pages 1-5 of the report for each of those records.  The following code seems to work with the exception that when the PrintOut method is invoked, the object tblCountFedExClaims is active and not the report object rptReceiptofClaim_LtrFEDEX that I want to print.  How can I make the report object active so that the printout method applies to it and not the table?

    DoCmd.OpenQuery "qryCountFedExClaims"
    Set rs = CurrentDb.OpenRecordset("tblCountFedExClaims")
    intNumRecords = rs!Count
    rs.Close
    Set rs = Nothing
       
    DoCmd.OpenReport "rptReceiptofClaim_LtrFEDEX", acPreview
    DoCmd.Minimize
           
    y = 1
    For x = 1 To intNumRecords
        'Print the first 5 pages for each SR
        DoCmd.PrintOut acPages, y, y + 4, acHigh
        'Set y = starting page of next SR
        y = y + 6
    Next x
   
    DoCmd.Close acReport, "rptReceiptofClaim_LtrFEDEX"
Avatar of Makr_Watson27
Makr_Watson27

Not offering  a solution, but perhaps if you looked at the report code, so it didn't display the data?
Why can't you create a query to display what you want in the report?
Avatar of rockiroads
Have u tried setting focus to the report after you open it

or pass in arguments
e.g.

    DoCmd.OpenReport "report1", acViewPreview, , , acHidden, y


then in the report code, u can check the args

Private Sub Report_Open(Cancel As Integer)
    Dim iCnt as Integer

    If IsNull(OpenArgs) = False Then
        iCnt = OpenArgs
        DoCmd.PrintOut acPages, iCnt, iCnt+4, acHigh
    End If
End Sub




so your code will look something like this


    y = 1
    For x = 1 To intNumRecords
        'Print the first 5 pages for each SR
        DoCmd.OpenReport "rptReceiptofClaim_LtrFEDEX", acViewPreview, , , acHidden, y
        DoCmd.Close acReport, "rptReceiptofClaim_LtrFEDEX"
        'Set y = starting page of next SR
        y = y + 6
    Next x

ASKER CERTIFIED SOLUTION
Avatar of stevbe
stevbe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jrimmele

ASKER

I originally tried the DCount function, but when it got to the line of code containing docmd.printout, I got an error that said something along the lines that the printout method was not available.  That is why I switched it to the way it is now.

One of two things seem to work:

1.  I moved the loop to the report's on activate event

2.  I kept the code where it is (under the click event for a command button on a form), but removed the minimize method.  Doing that also somehow allows the DCount function call to work as well.  I have no idea why, but if it works, it works.
It is based on the PrintOut command working on the *active* object from the application's perspective. When you minimize the report it no longer has the focus.

Steve