How to programmatically change paper bins when you print reports in Access 2002 by using Visual Basic for Applications (279506)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q279506
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

This article shows you how to programmatically change what paper bin that the printer uses when you print reports in Access 2002 by using Microsoft Visual Basic for Applications. For example, suppose that you want to print the first page of a report from a paper bin that supplies custom letterhead and the remaining pages of the report from a paper bin that supplies standard paper. The method in this article enables you to do so.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
  1. Open the sample database Northwind.mdb.
  2. Create a new, blank form.
  3. Add a command button to the form, and then set the OnClick property of the command button to the following event procedure:
    Private Sub Command0_Click()
        Dim strReportName As String
        Dim prt As Access.Printer
          
        strReportName = "Alphabetical List Of Products"
        
        'Open the report in design and change the paperbin property
        'to print from the lower bin
        DoCmd.OpenReport strReportName, acViewDesign
        Set prt = Reports(strReportName).Printer
        prt.PaperBin = acPRBNLower
    
        'Use the PrintOut method to print only the first page of the report
        DoCmd.PrintOut acPages, 1, 1
        
        'Change the PaperBin property to print from the upper bin
        prt.PaperBin = acPRBNUpper
        
        'Use the PrintOut method to print the remainder of the report.<BR/>
        'Here we use pages 2 through 32767. Since 32767 is the maximum number
        'of pages that can be printed, we can use it here to tell the code
        'to print all remaining pages,
        DoCmd.PrintOut acPages, 2, 32767
        DoCmd.Close acReport, strReportName, acSaveNo
    End Sub
    					
  4. Save the form and close it.
  5. Open the form in Form view.
  6. Click the command button.
Note that the report's first page is printed from the lower paper bin, but that the remainder of the report is printed from the upper paper bin.

REFERENCES

For more information about using the Printer object, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type printer object in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbprint kbReport kbdta kbhowto KB279506