I am trying to place code into my on click event of my print report button that will print a report to letterhead and plain paper. Ther are two drawers on the printer one is for letter and the other is for letterhead. Listed below is my code for accomplishing this task. One problem I have is that Access is looking for an end sub right away. It's almost like it does not recognize the function. Any help would be greatly appreciated.
Private Sub Print_Invoice_OnClick()
Function twotrayprinting(WAMInvoice) As Integer
'
'Note: The report gets run twice, once for each tray.
'
'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 WAMInvoice, A_DESIGN
'Switch to upper tray and print first copy
SetReportTray Reports(WAMInvoice), R_UPPR_Tray
DoCmd.PrintOut A_PAGES, MAX_PAGES
'Switch to lower tray and print second copy
SetReportTray Reports(WAMInvoice), R_Lower_tray
DoCmd.PrintOut A_PAGES, MAX_PAGES
'Close the report
DoCmd.SetWarnings False
DoCmd.Close A_REPORT, WAMInvoice
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
End Sub
Private Sub Print_Invoice_OnClick()
Function twotrayprinting(WAMInvoice) As Integer
'
'Note: The report gets run twice, once for each tray.
'
'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 WAMInvoice, A_DESIGN
'Switch to upper tray and print first copy
SetReportTray Reports(WAMInvoice), R_UPPR_Tray
DoCmd.PrintOut A_PAGES, MAX_PAGES
'Switch to lower tray and print second copy
SetReportTray Reports(WAMInvoice), R_Lower_tray
DoCmd.PrintOut A_PAGES, MAX_PAGES
'Close the report
DoCmd.SetWarnings False
DoCmd.Close A_REPORT, WAMInvoice
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
End Sub