report with print dailog

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,
 
C

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 reports prompt
for parameters, for when the user cancels the parameter prompt dialog.

Hope that helps,

Clifford Bass
 
I

inungh

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top