Solved

Make an object active for PrintOut Method

Posted on 2006-07-13
5
588 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

719 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