Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If User hits Esc Key during processing of VBA/SQL code... 1

Status
Not open for further replies.

cariengon

Technical User
Mar 18, 2002
283
US
Is there some code that recognized if the user hit the Esc key during VBA processing? I have some code that runs many different processes (queries and SQL). I've noticed that if I hit the ESC key in the middle, the current process stops and it moves on to the next. I want ALL of the processes to stop if this occurs, so I can reverse what has been done so far.

Thanks,
Carie

 
I have code for this, here is my example:

'Check if Escape key has been pressed, abort if true
If apiGetAsyncKeyState(VK_ESCAPE) Then
If MsgBox("Please Confirm that you pressed Escape!", vbYesNo, "Do you wish to stop?") = vbYes Then
Exit Function
End If
End If

This is within a loop so that every time the next event occurs it checks for the esc key.

Good luck! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Thank you so much for your quick response! I will try it immediately...

Carie
 
Anthony -

I tried this code, but when I went to compile I got the message that the Function was not defined.

I believe this would be the 'apiGetAsyncKeyState' function. Do you happen to know where I can obtain this? I don't have the MS sample database available to me right now....

Thanks!
Carie
 
Sorry, here it is!!

Public Declare Function apiGetAsyncKeyState Lib "user32" _
Alias "GetAsyncKeyState" _
(ByVal vKey As Long) _
As Integer


Good luck! Anthony J. DeSalvo
President - ScottTech Software
"Integrating Technology with Business"
 
Huh. That's pretty slick. Another way to go about this, I would think, would be to use transactions. If you check into transactions in the help file you'll see they're pretty easy to use and pretty darn powerful.

Jeremy ==
Jeremy Wallace
AlphaBet City Dataworks
Affordable Development, Professionally Done

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top