Solved

Make an object active for PrintOut Method

Posted on 2006-07-13
5
583 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

706 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now