Cancel Queries' Changes Before Operation Ends

INFOS

Registered User.
Local time
Today, 22:36
Joined
Jan 15, 2005
Messages
55
WHAT IS WRONG WITH THIS CODE:

Code:
Dim wsp As Workspace
Dim fInTrans As Boolean

On Error GoTo C4Err

fInTrans = False
Set wsp = DBEngine.Workspaces(0)

wsp.BeginTrans
fInTrans = True

DoCmd.OpenQuery "query1"
DoCmd.OpenQuery "query2"
DoCmd.OpenQuery "query3"
DoCmd.OpenQuery "query4"

wsp.CommitTrans

C4Exit:
Set wsp = Nothing
Exit Sub

C4Err:
MsgBox Err.Description
If fInTrans Then
wsp.Rollback
End If
Resume C4Exit

I WANT TO RUN 4 BIG APPEND QUERYS BUT IF USER PRESS ESCAPE BUTTON BEFORE ALL QUERYS ARE FINISHED - THEN ALL RECORD CHANGES MADE BY THOSE QUERYS MUST BE CANCELED.
SO I MADE THIS CODE. BUT IT DOES NOT WORK.
 
Last edited by a moderator:
Have you tried putting "fInTrans = False" before your On Error GoTo statement?
 
It's not that

Now, code is correct but this still does not work:
Code:
Dim wsp As Workspace
Dim fInTrans As Boolean

On Error GoTo C4Err

fInTrans = False
Set wsp = DBEngine.Workspaces(0)

wsp.BeginTrans
fInTrans = True

DoCmd.OpenQuery "query1"
DoCmd.OpenQuery "query2"
DoCmd.OpenQuery "query3"
DoCmd.OpenQuery "query4"

wsp.CommitTrans

C4Exit:
Set wsp = Nothing
Exit Sub

C4Err:
MsgBox Err.Description
If fInTrans Then
wsp.Rollback
End If
Resume C4Exit

WHY?
 
Last edited by a moderator:
does pressing escape trigger the error?

Peter
 
yes

Yes it is. And don't tell me to use autokeys. First, there is no autokeys symbol
for "escape" button ("Esc" does not work) and even if it works that causes me another problems...
 
I was not going to suggest trapping the keys I was just trying to get a better understanding of the problem.
As it stands then the code will run, Esc is pressed the query is cancelled, your error message box pops up but the queries are not rolled back.
Is that's what is happening?

Peter
 
reply

That's exactly what happens. Is there a way to block "escape" button until this code ends or to use "rollback" somehow?
 
only thing that comes to mind at the moment is to run the queries as sql code rather than saved queries. I don't think that Esc affects them.

Peter
 
Same thing

Escape button stops sql code same as saved query.
 
Trap the keycodes and turn vbKeyEscape into 0 during your query run.
 
How?

There is no way to capture escape key - at all!
Autokeys doesn't support escape key (and I need escape key on other places in my application). And you can not stop "escape key break" neather with keydown event nor with keypress event!
 
Did you set KeyPreview to Yes and use the OnKeyPress event?
 
I'm not sure what is going on in your system. I tried it and it works just fine in my system. Sorry. Maybe someone else has a suggestion.
 
Code

Send me please what exactly did you wrote in "on key press" event - the code.
Thanks!
 
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
   KeyAscii = 0
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom