Problem with filtering and printing report

platypus

New member
Local time
Yesterday, 23:18
Joined
Dec 11, 2011
Messages
3
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?:confused:

I am using Access 2003.
 
Last edited:
The simple question is, why is the query not executed from within the TwoTrayPrinting function? DoCmd.OpenReport ReportName, acViewDesign, "qryReviewLetter"

I just don't understand. Surely, someone here must understand the vagaries of MS Access better than me...no?
 
Perhaps the article here will be of assistance to you.

Also why not simply set your Query as the Record Source of your Report and use;
Code:
DoCmd.OpenReport ReportName, acViewDesign
 
Perhaps the article here will be of assistance to you.

Also why not simply set your Query as the Record Source of your Report and use;
Code:
DoCmd.OpenReport ReportName, acViewDesign

Great, the code from the Microsoft site works a treat after I worked out our printer's tray codes :)

Thank you!
 

Users who are viewing this thread

Back
Top Bottom