Escape as Cancel returns "The OpenForm Action was Cancelled."

bballhermit

Registered User.
Local time
Today, 08:17
Joined
Oct 14, 2010
Messages
40
I have some forms in my database that have the cancel command (which closes the current form and opens the parent form) set to "yes". Some work as expected when I press the escape key, but some return an "The OpenForm Action was Cancelled" error and terminate the session. Any ideas on what/where to check to fix this? Thanks.
 
I'm afraid I'm not familiar with the Cancel Command. Could you describe this just a bit more?
 
Sorry. I wasn't very clear. I had a custom "cancel command" that does as stated, but in the windows where I'm having trouble, I set the cancel property to "yes." This allows typically for the command or button with the cancel property set as "yes" to be triggered by pressing the escape key. Some of my forms work properly, but some return the error when pressing cancel.
 
What version of Access are you using? Is this an MDE? I feel real stupid right now as you are describing a feature of which I am not familiar. Maybe a sample db would help.
 
No worries. Thanks for your time. It's Access 2007. Basically, when I click on my "cancel" button in a form, in the "Other" tab of the properties there is an item called "cancel". Setting that to "yes" should denote that that button is what will be triggered when pressing the escape key in that form. This works properly on some of my forms, but triggers my aforementioned error on others... I can't really send a sample db, as my db is sensitive, but hopefully someone will be able to help. Thanks!
 
Okay, I'm now up to speed. I read about that years ago but never used it. What code do you have in the Click event of that Command Button?
 
Last edited:
Step through your code. It sounds like this button is programmed to also open a form or report too. If this is the case then the Cancel property is conflicting with the OpenReport/OpenForm command.
 
Here is my code for one of the forms. On this form, there is a "cancel" button that runs cmdCancel_Click(). On this button, I have the cancel property set to yes. Could you help me determine where it is that I am getting this "The OpenForm action was canceled." error when I press the escape key? Thanks.

Code:
Option Compare Database
'Add New Employee to Database and Return to Employee Management Form
Private Sub cmdAdd_Click()
On Error GoTo Err_cmdAdd_Click
    
    If (IsNull([FirstName]) = True) Or (IsNull([LastName]) = True) Or (IsNull([Rate]) = True) Then
        MsgBox "One or more required fields are empty.", vbCritical, "Infoscitex Corporation PMBS"
        Exit Sub
    Else
        DoCmd.Close
    End If

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "fmnuEmployees"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdAdd_Click:
    Exit Sub

Err_cmdAdd_Click:
    MsgBox Err.Description
    Resume Exit_cmdAdd_Click
    
End Sub
'Cancel Adding New Employee and Return to Employee Management Form
Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click
    
    If (IsNull([FirstName]) = False) Or (IsNull([LastName]) = False) Or (IsNull([Rate]) = False) Or (IsNull([Email]) = False) Then
        DoCmd.RunCommand acCmdDeleteRecord
    End If
    
    DoCmd.Close
    
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "fmnuEmployees"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdCancel_Click:
    Exit Sub

Err_cmdCancel_Click:
    MsgBox Err.Description
    Resume Exit_cmdCancel_Click

End Sub
 
any form that doesn't open causes a cancel error (error no. 2501)

You need to intercept this error, and dismiss it.

I think that is proably the cause of the problem
 
Could you point me to how or explain to me how I could intercept this error? Thanks.
 
in this bit of code, add the error number

Code:
Err_cmdCancel_Click:
    MsgBox "Error: " & err & "    Desc: " &  Err.Description
    Resume Exit_cmdCancel_Click

assuming you ARE seeing error 2501 you can then say

Code:
Err_cmdCancel_Click:
   [COLOR="Red"] if err<>2501 then [/COLOR]MsgBox "Error: " & err & "    Desc: " &  Err.Description
    Resume Exit_cmdCancel_Click
 
Setting a button "Cancel" property to true make it to close the form by pressing the ESC key.
if you do that you should only close the forn using this button.
 

Users who are viewing this thread

Back
Top Bottom