I have a form with a button that runs this code:
Private Sub Command645_Click()
On Error GoTo Err_Command645_Click
Dim stDocName As String
stDocName = "myLetter"
'Calling TwoTrayPrinting function from SelectPrinterTray Module
' to select letter head tray for first page of report plain paper tray for remaining pages
TwoTrayPrinting (stDocName)
Exit_Command645_Click:
Exit Sub
Err_Command645_Click:
MsgBox Err.Description
Resume Exit_Command645_Click
End Sub
The TwoTrayPrinting function is:
Function TwoTrayPrinting(ReportName As String) As Integer
' Prints a report's page 1 from the letterhead tray
' and the remaining pages from the plain paper 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
'Dim rptLetter As Report
' Open the report in DESIGN view
On Error GoTo TTP_Error
DoCmd.Echo False
DoCmd.OpenReport ReportName, acViewDesign, "qryReviewLetter"
'Referencing the open document
'Set rptPrintLetter = Reports(ReportName)
' Switch to letterhead tray and print first page
SetReportTray Reports(ReportName), R_LETTERHEAD_TRAY
DoCmd.PrintOut A_PAGES, 1, 1
'Switch to plain paper tray and print remaining pages
SetReportTray Reports(ReportName), R_PLAINPAPER_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
The problem is that it does not execute DoCmd.OpenReport ReportName, acViewDesign, "qryReviewLetter" to filter the report as selected in the form. It prints all records instead. Why?
I am using Access 2003.
Private Sub Command645_Click()
On Error GoTo Err_Command645_Click
Dim stDocName As String
stDocName = "myLetter"
'Calling TwoTrayPrinting function from SelectPrinterTray Module
' to select letter head tray for first page of report plain paper tray for remaining pages
TwoTrayPrinting (stDocName)
Exit_Command645_Click:
Exit Sub
Err_Command645_Click:
MsgBox Err.Description
Resume Exit_Command645_Click
End Sub
The TwoTrayPrinting function is:
Function TwoTrayPrinting(ReportName As String) As Integer
' Prints a report's page 1 from the letterhead tray
' and the remaining pages from the plain paper 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
'Dim rptLetter As Report
' Open the report in DESIGN view
On Error GoTo TTP_Error
DoCmd.Echo False
DoCmd.OpenReport ReportName, acViewDesign, "qryReviewLetter"
'Referencing the open document
'Set rptPrintLetter = Reports(ReportName)
' Switch to letterhead tray and print first page
SetReportTray Reports(ReportName), R_LETTERHEAD_TRAY
DoCmd.PrintOut A_PAGES, 1, 1
'Switch to plain paper tray and print remaining pages
SetReportTray Reports(ReportName), R_PLAINPAPER_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
The problem is that it does not execute DoCmd.OpenReport ReportName, acViewDesign, "qryReviewLetter" to filter the report as selected in the form. It prints all records instead. Why?
I am using Access 2003.
Last edited: