Brett Kinross said:
I have a form that we regularly print. However sometimes we require that the
tray is set to the Automatic tray and other times to print from the Manual
tray. Is there an easy way to change this setting through VBA?
Here's some code I pulled off the newsgroups probably 7 or 8 years ago. I
have not tested it, but it looks good (which is why I grabbed it). I don't
have the author's name.
Switch printer trays on a report basis(report 1 prints from tray 1, report2
prints from tray 2 etc)
-------------
Option Compare Database
Option Explicit
Const R_UPPER_TRAY = 1
Const R_LOWER_TRAY = 2
Type str_DEVMODE
RGB As String * 94
End Type
Type type_DEVMODE
strDeviceName As String * 16
intSpecVersion As Integer
intDriverVersion As Integer
intSize As Integer
intDriverExtra As Integer
lngFields As Long
intOrientation As Integer
intPaperSize As Integer
intPaperLength As Integer
intPaperWidth As Integer
intScale As Integer
intCopies As Integer
intDefaultSource As Integer
intPrintQuality As Integer
intColor As Integer
intDuplex As Integer
intResolution As Integer
intTTOption As Integer
intCollate As Integer
strFormName As String * 16
lngPad As Long
lngBits As Long
lngPW As Long
lngPH As Long
lngDFI As Long
lngDFr As Long
End Type
Sub SetReportTray(r As Report, traynumber As Integer)
'
' Changes the tray number of a report that is opened in DESIGN mode
'
Dim DM As str_DEVMODE 'R_DevModeStr
Dim DevMode As type_DEVMODE
'MsgBox "test"
If Not IsNull(r.PrtDevMode) Then
DM.RGB = r.PrtDevMode
LSet DevMode = DM
DevMode.intDefaultSource = traynumber
LSet DM = DevMode
r.PrtDevMode = DM.RGB
End If
End Sub
Function TwoTrayPrinting(ReportName As String) As Integer
'
' Prints a report's page 1 from the upper tray
' and the remaining pages from the lower tray.
' NOTE: The report gets run twice, once for each tray.
'
' Assumes: that the report has 999 or fewer pages.
'
' Returns: TRUE = Success; FALSE = Error
'
Const MAX_PAGES = 999
' Open the report in DESIGN view
On Error GoTo TTP_Error
DoCmd.Echo False
DoCmd.OpenReport ReportName, A_DESIGN
' Switch to upper tray and print first page
SetReportTray Reports(ReportName), R_UPPER_TRAY
DoCmd.PrintOut A_PAGES, 1, 1
' Switch to lower tray and print remaining pages
SetReportTray Reports(ReportName), R_LOWER_TRAY
DoCmd.PrintOut A_PAGES, 2, MAX_PAGES
' Close the report
DoCmd.SetWarnings False
DoCmd.Close A_REPORT, ReportName
DoCmd.SetWarnings True
DoCmd.Echo True
'TwoTrayPrinting = True
TTP_Exit:
Exit Function
TTP_Error:
' TwoTrayPrinting = False
DoCmd.Echo False ' Restore screen echo
Resume TTP_Exit
End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access Downloads
http://www.datastrat.com
http://www.mvps.org/access