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.
- 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
' 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
- 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.