Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Print a Report to Different Paper Trays


View products that this article applies to.

Summary

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

This article shows you how to create a sample user-defined Visual Basic for Applications procedure that uses the PrtDevMode property to set different paper tray sources for the pages of a report.

↑ Back to the top


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. When you use the PrtDevMode property, keep the following printer driver characteristics in mind:
  • Set only those members that the printer driver supports. For example, if you set a custom page size for a driver that does not support a custom page size, you may encounter unexpected results.
  • Set the PrtDevMode property's Fields member if you change any other member to let the printer driver know which members you are changing.
  • Change only the first 68 bytes of the PrtDevMode property. Printer drivers are able to store driver-specific information after the first 68 bytes; therefore, it is important not to overwrite this information.
This article assumes that you want to print the first page of your report from one paper source and the second page of your report from another paper source.

Steps for Printing Pages of Report from Different Paper Trays

  1. Open the sample database Northwind.mdb.
  2. Create a new module and type the following information in the Declarations section of the module:
    Type zwtDevModeStr
       RGB As String * 94
    End Type
    
    Type zwtDeviceMode
       dmDeviceName As String * 16
       dmSpecVersion As Integer
       dmDriverVersion As Integer
       dmSize As Integer
       dmDriverExtra As Integer
       dmFields As Long
       dmOrientation As Integer
       dmPaperSize As Integer
       dmPaperlength As Integer
       dmPaperWidth As Integer
       dmScale As Integer
       dmCopies As Integer
       dmDefaultSource As Integer
       dmPrintQuality As Integer
       dmColor As Integer
       dmDuplex As Integer
       dmResolution As Integer
       dmTTOption As Integer
       dmCollate As Integer
       dmFormName As String * 16
       dmPad As Long
       dmBits As Long
       dmPW As Long
       dmDFI As Long
       dmDRr As Long
    End Type
    
    					
  3. Type the following procedure:
    Sub setPaperSource(rptName As String)
       Dim Rpt As Report
       Dim dm As zwtDeviceMode
       Dim DevString As zwtDevModeStr
       Dim DevModeExtra As String
          
       DoCmd.SetWarnings False
       ' Set Paper Tray for page 1
       DoCmd.OpenReport rptName, acDesign
       Set Rpt = Reports(rptName)
       DevModeExtra = Rpt.PrtDevMode
       DevString.RGB = DevModeExtra
       LSet dm = DevString
       dm.dmDefaultSource = 2  '1 = Upper Tray, 2 = Lower Tray, 5 = _
          Envelope Feeder
       LSet DevString = dm
       Mid$(DevModeExtra, 1, 68) = DevString.RGB
       Rpt.PrtDevMode = DevModeExtra
       DoCmd.Save acReport, Rpt.Name
       DoCmd.SelectObject acReport, Rpt.Name, True
       DoCmd.PrintOut acPages, 1, 1
          
       ' Set Paper Tray for page 2
       DoCmd.OpenReport rptName, acDesign
       Set Rpt = Reports(rptName)
       DevModeExtra = Rpt.PrtDevMode
       DevString.RGB = DevModeExtra
       LSet dm = DevString
       dm.dmDefaultSource = 1  '1 = Upper Tray, 2 = Lower Tray, 5 = _
          Envelope Feeder
       LSet DevString = dm
       Mid$(DevModeExtra, 1, 68) = DevString.RGB
       Rpt.PrtDevMode = DevModeExtra
       DoCmd.Save acReport, Rpt.Name
       DoCmd.SelectObject acReport, Rpt.Name, True
       DoCmd.PrintOut acPages, 2, 2
       DoCmd.SetWarnings True
    End Sub
    					
  4. To test this procedure, type the following line in the Immediate window, and then press ENTER:
    setPaperSource("Invoice")
    						
    Note that the first two pages of the Invoice report print. The first page prints from the lower tray and the second page prints from the upper tray.

↑ Back to the top


References

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


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

↑ Back to the top


Keywords: KB200546, kbprint, kbhowto

↑ Back to the top

Article Info
Article ID : 200546
Revision : 3
Created on : 6/23/2005
Published on : 6/23/2005
Exists online : False
Views : 393