[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Equivalent of Excel's EnableCancelKey in Access?

Posted on 2013-01-05
4
Medium Priority
?
1,374 Views
Last Modified: 2013-03-01
I want the user of an Access database to be able to interrupt and exit procedures that involve long loops.

I could trap the KeyDown event of <Escape> so that it changes the value of a global variable whose value gets checked within the loop and so permits code execution to pass out of it, but that would slow down the procedure even further.

Does Access have an equivalent of Excel's Application.EnableCancelKey property (set to xlErrorHandler would do the trick), or does anyone have their own improvised equivalent?

Thanks.
0
Comment
Question by:TimHudspith
4 Comments
 
LVL 40

Expert Comment

by:als315
ID: 38746396
You can interrupt execution with Ctrl+Break keys.
0
 

Author Comment

by:TimHudspith
ID: 38746402
But that's not a proper solution is it? Variables and objects in the procedure don't get cleaned up properly.
0
 
LVL 29

Assisted Solution

by:IrogSinta
IrogSinta earned 750 total points
ID: 38746785
I don't believe there is.  I would do it the same way as you mentioned although I would keep the scope of the variable just to the form alone (Dim it the top of the form's module).  Of course you would need to add the DoEvents command in your loop so that the Escape key press could be captured, it sounds like you're already aware of this.
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 750 total points
ID: 38751210
<Variables and objects in the procedure don't get cleaned up properly. >
AFAICT, EnableCancelKey does not do this either...
http://msdn.microsoft.com/en-us/library/office/aa214566%28v=office.11%29.aspx

To detect if the ESC key was pressed, you can use something like this:
Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 27 Then
        MsgBox "Put code here to clean up variables, alert the user, and exit gracefully."
        'MsgBox "You pressed the ESC key"
    End If
End Sub


JeffCoachman
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question