Access: Canceling Report generation causes error 2501

送分小仙女□ 提交于 2021-02-10 19:51:56

问题


can't believe I am losing so much time on this one.

I have an order form, and when I click on a button "reports", a dialog pop ups with a list of different reports to chose from. Double-clicking selects and starts the correspondent report.

On one of these reports, there is an unbound text box I need the user to enter data with. The ControlSource of this field is set to its Name property. When the report is started, an input box appears with an OK and a Cancel button. Whenever I enter some data, all is fine.

But when I click on Cancel, the app crashes and I get an errormessage: "Runtime Error 2501: The Action OpenReport has been canceled" (translated from German).

The Report is called through this code:

DoCmd.OpenReport vBerichtName, nAnsicht
End If   

On Error Resume Next
  DoCmd.Close acForm, "F_BerichtDrucken"
On Error GoTo 0

1) Why does the error handling not kick in?
2) I googled and found lots of weird solutions for this, like the official Microsoft one saying you need to install/update a printer driver (come on...). None helped.

I am doing this for a friend and I normally work on linux/php,java, etc. I apologize if the solution is somewhat obvious or something like that.


回答1:


Ditto to Phillipe's answer. you didn't give us the whole procedures but you need to do something like this...

Sub MyButton_Click
On Error Goto myError

DoCmd.OpenReport vBerichtName, nAnsicht


MyExit:
   Exit Sub

MyError:
   If Err.number = 2501 then goto myExit
   msgbox err.description
   goto myExit

End Sub

This is a common error but you can catch it like any other error and ignore it if is 2501.
Seth




回答2:


The error probably comes from the DoCmd.OpenReport line. This is why the error handler does not work.

I guess the value you requested is somehow mandatory in the report. Did you try to put your error management line before the docmd.openReport?




回答3:


Check your default printer. I was getting the same error & all my code was working properly. Someone using the computer set the default printer to a label printer. Somehow Access was checking the printer & knew it didn't have the correct size settings to print so it stopped the displaying of the report.

I changed the default printer to another full size sheet printer and it worked fine.

I hope this helps someone because I was at a loss when it first occurred.




回答4:


OK, it works now.

After your suggestions, I put the code like this:

    On Error GoTo CancelError 
    If Not IsNull(vFilter) Then 
       DoCmd.OpenReport vBerichtName, nAnsicht, , vFilter 
    Else 
       DoCmd.OpenReport vBerichtName, nAnsicht 
    End If
CancelError:
  DoCmd.Close acReport, vBerichtName
  DoCmd.Close acForm, "F_BerichtDrucken"
  Echo True  ' this did the trick 
  Exit Function 

As soon as I put Echo True into the error handling, it works now smoothly, going back to the previous form and allowing to continue to work - looks like "Echo" is kind of a refresher for the screen...?



来源:https://stackoverflow.com/questions/1492231/access-canceling-report-generation-causes-error-2501

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!