you don't have the license required to use htis activex control

I

icccapital

I am using Access 2007 and wanted to add the microsoft common dialog control
to a form so I could have a print dialog box pop up when my print button is
clicked. Couple of questions:

1)Can I get the print dialog to show up using vba in a different way?
2)How do I fix this error?

Either or both questions are welcome. Thank you.
 
C

Clifford Bass

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
 

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