Hi,
Yes to #1. Here is how: In a regular module; not a class, form or
report module; add this subroutine:
Public Sub PrintAReportShowingPrintDialog(ByVal strReportName As String)
On Error GoTo Handle_Error
DoCmd.OpenReport strReportName, acViewPreview
DoCmd.RunCommand acCmdPrint
Exit_Sub:
On Error Resume Next
DoCmd.Close acReport, strReportName, acSaveNo
Exit Sub
Handle_Error:
If Err.Number <> 2501 Then
' 2501 occurs when user cancels the print dialog box
MsgBox "Error #" & Err.Number & ": " & Err.Description
End If
Resume Exit_Sub
End Sub
Then in your button's On Click event use something like this:
PrintAReportShowingPrintDialog "rptMy Report's Name"
It can be called from anywhere so if you want to do the same elsewhere,
you only need to call it as shown above in each of those places. Essentially
the subroutine opens the report, mimics the user choosing Print from the menu
and then closes the report. It needs to have the error handling that you see
in it so as to catch when the user cancels the print dialog. If your
report's query prompts for parameters, you will want to test out what happens
when the parameter dialog is cancelled. If it returns with a different error
number and message you can filter out that error number in the Handle_Error
part of the code.
Clifford Bass