Open the Report in acPreview with your code ... don't worry, it will not appear on screen if you follow the instructions below.
Add the following to the "On Activate" event of the report.
This will cause the Print Dialog Box to open so you can choose a printer, and also choose the number of copies .... ect.
After you make the choices in the Printer Dialog Box the report will print ... but the code will close the report without it ever appearing on screen.
There is also code here in case the result of the recordset returns "no records" so there's no need to use the On No Data event. It will display a message box that you can alter to fit your needs.
code:
Private Sub Report_Activate()
On Error GoTo Err_Report_Activate
Dim strMsg As String
Dim strTitle As String
strMsg = "The Were No Records Returned." & vbCrLf & _
"Print has been Canceled."
strTitle = " No Records Returned"
If Me.Report.HasData Then
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, Me.Name
Else
MsgBox strMsg, vbInformation + vbOKOnly, strTitle
DoCmd.Close acReport, Me.Name
End If
Err_Report_Activate:
Resume Next
DoCmd.Close acReport, Me.Name
End Sub
VBAINCHICAGO