Cancel Query / error trapping

china99boy

Registered User.
Local time
Yesterday, 19:57
Joined
Apr 27, 2006
Messages
161
Ok, I have a delete query that I use to delete records form a table. I have created a form that I run that query from. It has Delete button that runs the query. After I get the message that says "You are about to delete 56 records" and I click No, I get a "run-time error '3059'. Operation Cancel by user"

I did some searching on the forum and thought I could trap this error. But I still continue to get the error at

"DoCmd.OpenQuery stDocName, acNormal, acEdit"

What am I doing wrong and how can I prevent this error from appearing when I click NO or cancel the operation.

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

Dim stDocName As String

stDocName = "qryDeleteRecords"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_cmdDelete_Click:
Exit Sub

cmdDelete_Error:
Select Case Err.Number
Case 3059
MsgBox "You have canceled the delete operation.", vbOKOnly, "Delete Canceled"
Exit Sub
Case Else
MsgBox "Error number: " & Err.Number & " has occurred. " & Err.Description, vbOKOnly, "Error"
End Select

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub
 
If you use CurrentDb.Execute to run your action query you are not asked those questions. Do you really want to cancel the delete sometimes? You should really determine that before you run the query.
 
Cancel Key Breaks Out Of Code

I have a strange problem related to this post that I would love some help with. As a background, the code base I am referring to here is a commercial database distributed under Access Runtime
2003 for a number of years now without issue.

Upon converting this application to Access Runtime 2007 and distributing it, the code all apparently works well except that I am
seeing some strange behavior, specifically, that if you hit the <ESC> key on the keyboard at any time when some module code is
running (e.g. when saving an order or adding a contact) then Access immediately stops what it is doing in the background and
indicates that the User has canceled the operation (error #3059).

Essentially as long as the user keeps his hands off the keyboard, all works well. This was not a problem in Access 2003 and the
code is the same so something must be different in the environment.

I have explored several options such as:
1) DoCmd.SetWarnings False when the application first opens (Result= no effect - msg came up regardless so this 3059 is
apparently not considered a warning and is more of an error)
2) Using the AutoKeys macro to intercept the {ESC} key (Result= wasn't allowed. Apparently only a subset of the SendKeys
character set can be used in this macro and the {ESC} key is not one of them)
3) Trying to suppress the error using the OnError function in the forms (Result=no effect - msg would come up without being
trapped)

My questions:
*Can anyone help me understand why this is different from the 2003 environment?
*Is there a way to disable the keyboard during code exec?
*Any other ideas on what I can do?!

Thanks in advance
Jerry :confused:
 
Welcome to Access World Forums. You should really start a new thread with this post so everyone can see it and you will get a better response. It sounds like an a2007 RunTime issue.
 

Users who are viewing this thread

Back
Top Bottom