Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep getting Error 2501?

Calendars

Keep getting Error 2501?

by  Andino  Posted    (Edited  )
Having seen a number of people asking about Error 2501.

This Access error says:

[tt]"The OpenForm action was cancelled"
"You used a method of the DoCmd object in Visual Basic, but then clicked Cancel in a dialog box"[/tt]

It normally occurs when you try to open a form in Visual Basic using the [tt]DoCmd.OpenForm[/tt] statement.

The main problem is what is tells you is not necessarily true! You don't have to click Cancel in a dialog box for the error to occur.

One of the main reasons for the error is trying to open a form with incorrect Visual Basic behind it. For example,

If I try to open [tt]frmSecond[/tt] from [tt]frmFirst[/tt] using: [tt]DoCmd.OpenForm "frmSecond"[/tt] somewhere in the code module of [tt]frmFirst[/tt], but I have accidentally typed the following code somewhere in the code module of [tt]frmSecond[/tt]:

Code:
Private Sub btnMyButton_Click()
Private Sub btnMyButton_Click()

...

End Sub

The call to [tt]DoCmd.OpenForm "frmSecond"[/tt] causes Error 2501, as the Visual Basic error I have caused by writing [tt]Private Sub btnMyButton_Click()[/tt] twice in [tt]frmSecond[/tt] prevented the form from opening.

You didn't click Cancel, but Access effectively did! When opening the form, Access checks that the Visual Basic is correct. If it's not, the form won't open, causing Error 2501.

An easy way to check that this is your cause, is to open the form (i.e. frmSecond above) manually and see if it'll open. If you can't open it, chances are Access can't either!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top