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!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.