Solved

Make an object active for PrintOut Method

Posted on 2006-07-13
5
585 Views
Last Modified: 2010-05-18
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"
0
Comment
Question by:jrimmele
5 Comments
 
LVL 7

Expert Comment

by:Makr_Watson27
ID: 17104800
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?
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17106146
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

0
 
LVL 39

Accepted Solution

by:
stevbe earned 500 total points
ID: 17107594
you could grab the count directly without opening a query / table/ recordset
you may also be having problems because of the "minimize", the app may be setting the focus to whatever the last thing you were looking at is ... namely tblCountFedExClaims.


    intNumRecords = DLookup("Count", "qryCountFedExClaims")
    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"
0
 

Author Comment

by:jrimmele
ID: 17108659
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.
0
 
LVL 39

Expert Comment

by:stevbe
ID: 17108684
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
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question