Solved

Equivalent of Excel's EnableCancelKey in Access?

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OCT or Config.xml 2 32
Before insert Image (OLE) resize image 11 41
ms office troubleshooting for users 8 33
I need to be able to get MAX(date)-1 from table. 4 24
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

929 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

11 Experts available now in Live!

Get 1:1 Help Now