Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Make an object active for PrintOut Method

Posted on 2006-07-13
5
Medium Priority
?
590 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

636 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