report with print dailog

  • Thread starter Thread starter iccsi
  • Start date Start date
I

iccsi

I wanted to have my report direct to printer and give user a printer
dialog to let user selcect printer to print.

Are there any controls available to use?

Your help is great appreciated,
 
Hi,

You could use this subroutine, placed in a regular (not class, not
report, not form) module:

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 when you want to print, simply use:

PrintAReportShowingPrintDialog "rptMyReportName"

You may need to add more error numbers to check if any reports prompt
for parameters, for when the user cancels the parameter prompt dialog.

Hope that helps,

Clifford Bass
 
Hi,

     You could use this subroutine, placed in a regular (not class,not
report, not form) module:

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 when you want to print, simply use:

PrintAReportShowingPrintDialog "rptMyReportName"

     You may need to add more error numbers to check if any reportsprompt
for parameters, for when the user cancels the parameter prompt dialog.

     Hope that helps,

             Clifford Bass







- Show quoted text -

Thanks millions,
 
Back
Top