Disable escape from stopping currently running action queries (1 Viewer)

panchitocarioca

Registered User.
Local time
Today, 04:05
Joined
Aug 11, 2008
Messages
11
Hi,

I have a small question. I have a database in which in the background action queries (through vba docmd.runsql "insert etc....") are run in some situations (the user does not see it happening). However, by pressing escape, the action queries can be cancelled. I would like to prevent this from happening. Is there any way to disable the escape key?

I have tried the "standard solution" to disable the escape key. In the form from which the action queries are run, i have put in the "on key down" event the following code (and put the keypreview to yes):

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then ' 27 is the Escape Key
* KeyCode = 0
End If
End Sub

However, the above code does not prevent pressing escape from stopping the action queries. It only prevents that changes in a form that have not been saved can be "undone" by pressing the escape key.

Anybody got any idea?

Many thanks in advance.

Best regards,
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:05
Joined
Sep 12, 2006
Messages
15,756
before you run the queries put

docmd.setwarnings false

after the query put

docmd.setwarnings true

this suppresses the user's ability to interact with the query, and thereby "stop" it.

--------
as you don't get warnnig messages, you don't get informed of (partial) failure, so if this is important look at

currentdb.execute "queryname" instead
 

panchitocarioca

Registered User.
Local time
Today, 04:05
Joined
Aug 11, 2008
Messages
11
Dear Gemma,

Many thanks for the feedback and apologies for my late reply. I had already switched of the warning by using docmd.setwarnings = false. That stops the program from asking the user for confirmation to run the action queries. However, it does not disable the possibility to interrupt the VBA code and action queries when they are being executed.

I have replaced docmd.runsql with currentdb.execute and it is unfortunately also not the solution. When VBA code is running and action queries are being executed you can still interrupt this process by pressing escape.

Does anyone have an idea how to prevent escape from interrupting the VBA code and action queries?

Once again, many thanks in advance.
 

Users who are viewing this thread

Top Bottom