Cancel RunCommand acCmdPrint Error 2501

supmktg

Registered User.
Local time
Today, 15:40
Joined
Mar 25, 2002
Messages
360
I'm unable to trap an Error 2501 that occurs when I cancel the acCmdPrint print dialog.

Here's my code:
Code:
Private Sub CmdPrint_Click()
    On Error GoTo CmdPrint_Click_Error

If Forms![frmEquipmentRates]![FrameSort] = 1 Then
DoCmd.OpenReport "rptEquipRateAlpha", acViewPreview
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, "rptEquipRateAlpha"
Else
DoCmd.OpenReport "rptEquipRateNum", acViewPreview
DoCmd.RunCommand acCmdPrint
DoCmd.Close acReport, "rptEquipRateNum"
End If
 
    CmdPrint_Click_Error:
      If Err.Number = 2501 Then
      Err.Clear
      Else
      MsgBox "Error " & Err.Number & " (" & Err.Description & ")"
      End If

End Sub

The error I get is a Microsoft Visual Basic Error:

Run-Time error '2501':

The RunCommand action was canceled.

The error seems to pop up before it gets to my 'CmdPrint_Click_Error:'. It appears to be generated by the print dialog.

How can I trap this error?

Thanks, Sup
 
Why are you using DoCmd.RunCommand acCmdPrint?

You don't need to. You can print by just using acViewNormal instead of acViewPreview. Plus then you don't have to close the report either.
 
Wow, that was fast Bob!

I am using DoCmd.RunCommand acCmdPrint so I can choose my printer and # of copies, Etc.

Sup
 
Hmm, the error handling seems to work for me (I took your code and modified it to fit a report that I had in my test db). Have you tried importing everything into a new mdb file?

You should also have an Exit Sub before the error handler so it will not generate an err.number of 0 when it gets down there when you let it run normally.
 
I copied everything into a new mdb. I still get the error!

Any ideas?

Sup
 
Attached is a new mdb with nothing but one table, one report and one form to test the error. I still get the error when I cancel the print dialog!

What am I doing wrong?

Sup
 

Attachments

Sup -

Sorry it has taken so long to get back to you but I had to wait until I was off work. The file you posted isn't working for me. I think you might have Maximum Compression enabled, which seems to cause a problem for some zip utilities. Can you rezip it and make sure to use Standard Compression?
 
Bob,

Here's a new zipped file.

This is very strange, I just tried this test file and the cancel error is Not there. So I tried my real file, and the error IS there. So I tried my test file again, and the error is BACK.

I guess my code is OK, but something else is causing this error to appear in my real file and if I leave the code window open it causes the error in my test file.

Where do I look to solve this?

Sup
 

Attachments

It is strange indeed because it works for me just fine. I would ask, do you have the Break on ALL errors enabled or Break on Unhandled errors?
 
Bob,

You are good! I was set to break on all errors. I set it to Break on unhandled errors and that fixed it.

Thanks so much,

Sup
 
Bob,

You are good! I was set to break on all errors. I set it to Break on unhandled errors and that fixed it.

Thanks so much,

Sup

Whew!! Glad we got that one sorted! It can be a bear troubleshooting sometimes. :)
 
Thanks Sup and Bob... I had the same problem... but I have another one: in the Print dialog box appears a cmdbutton "Configuration..." (or similar, I have office in spanish), the thing is that I cannot use that button
¿would you please help me?
 

Users who are viewing this thread

Back
Top Bottom