ACC97: How to Print a Report to Different Paper Trays

ID: Q179321


The information in this article applies to:
  • Microsoft Access versions 2.0, 7.0, 97


SUMMARY

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

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 (or NWIND.MDB in Microsoft Access 2.0).


  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 'DoCmd SetWarnings in Microsoft Access 2.0
             ' Set Paper Tray for page 1
             DoCmd.OpenReport rptName, acDesign
             ' Docmd OpenReport in Microsoft Access 2.0
             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 A_REPORT, Rpt.Name, True
             DoCmd.PrintOut A_PAGES, 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 A_REPORT, Rpt.Name
             DoCmd.SelectObject A_REPORT, Rpt.Name, True
             DoCmd.PrintOut A_PAGES, 2, 2
             DoCmd.Close     ' Closes the report
             DoCmd.SetWarnings True
    
          End Sub 
  6. To test this procedure, type the following line in the Debug window, and then press ENTER:
    
    setPaperSource("Invoice") 
    Note that the first two pages of the Invoice report prints. The first page prints from the lower tray and the second page prints from the upper tray.



REFERENCES

For more information about PrtDevMode and PrtDevNames, search for "PrtDevMode property" or "PrtDevNames property," using the Microsoft Access 97 Help Index or please visit the following Web site:

http://www.microsoft.com/AccessDev/Articles/GetzCh10.HTM

Additional query words: printing

Keywords : kbprint RptOthr RptProp
Version : WINDOWS:2.0,7.0,97
Platform : WINDOWS
Issue type : kbhowto


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