Solved

Equivalent of Excel's EnableCancelKey in Access?

Posted on 2013-01-05
4
1,151 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 39

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 250 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 250 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS Access Bound Objects. 6 28
Loop within Select Case 3 27
add more styles to my code 2 19
how to open abcd.txt.orig file? 10 7
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Outlook Free & Paid Tools
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now