ACC2000: How to Print a Report to Different Paper Trays

ID: Q200546


The information in this article applies to:
  • Microsoft Access 2000


SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and 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.


MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may want to contact a Microsoft Certified Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Solution Providers, please see the following page on the World Wide Web:

http://www.microsoft.com/mcsp/
For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

http://www.microsoft.com/support/supportnet/overview/overview.asp
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:


  3. 
    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
     
  4. Type the following procedure:


  5. 
    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 
  6. 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.



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.

Additional query words: printing

Keywords : kbprint kbdta AccCon RptOthr RptProp KbVBA
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: October 27, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.