Microsoft KB Archive/179321

= ACC97: How to Print a Report to Different Paper Trays =

Article ID: 179321

Article Last Modified on 8/17/2007

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q179321



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



SUMMARY
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. 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
 Open the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 2.0).  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   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 '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   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. 

