Solved

Equivalent of Excel's EnableCancelKey in Access?

Posted on 2013-01-05
4
1,253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

726 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