Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print Dialog Box

Status
Not open for further replies.
Nov 24, 2003
57
US
Does anyone know how to create a print dialog box for a report? I don't want to open the reports in preview, I want them to print when the user clicks on the button but first I want a print dialog box to appear so they can select which printer and tray to use. Thanks.
 
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
 
Thanks, but it's still not working. What happens is that it returns a message saying that theres no data even though there is. I played around with it a little and can get the print dialog box to appear but the report remains open. Any other ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top