DIsabling Escape Key while dialog active

R

Romulus

Hello

Does anyone know of a simple way to disable the "Escape"
key while a dialog box is displayed?

I imagine it would require an API call - any thoughts?

TIA

Romulus
 
H

Harald Staff

My thoughts in general is that programming like this is hijacking the computer, not good.
What you should do is respond reasonably to any keypress that Windows himself doesn't
handle.

Which dialog is it ? What happens on Esc that you want to avoid ?
 
T

Tom Ogilvy

Set the cancel property of a commandbutton to True. The click event for
that button will be fired if the user hits escape with the userform active.

I agree with Harald, but this is not hijacking the functionality as it is
the intended functionality.
 
A

Adiv

You could also include the following code in the form's Load event:

Application.OnKey "{ESCAPE}",""

(setting the procedure name to a zero length string disables the key)

Then to restore the ESC key, include this code in the form's Unloa
event:

Application.OnKey "{ESCAPE}"

(omitting the procedure name altogether restores the origina
functionality of the key)

Hope this helps. :cool
 
T

Tom Ogilvy

You might want to test this, because it doesn't appear to work for a
userform (when the userform has the focus). (just as onkey doesn't work when
your in edit mode)

A userform still gets the escape key when the userform has the focus.

That is the expected behavior and testing in xl97 shows it to be true.

Tested in xl2000, both modal and modeless. In modeless, when I click in the
sheet, the onkey is in effect, but when the focus is on the userform, the
userform handles the escape key. I would assume this is no different in
xl2002 or 2003 as this is the advertised behavior.

Hope that helps.
 
R

Romulus

Thanks Folks

I think I could have been clearer in my original post.
The dialog is displayed and acts as an interface for
users to enter data onto a temporary spreadsheet. when
They're done, they click a button that transfers that
data to a master data file.

I have programmed the dialogs without the top right 'X'
button, but the "Escape" key enables users to dismiss the
dialog, and it is this I want to avoid. Is there a way
to do this?
 
H

Harald Staff

Ok, the good old DialogSheets ? I doubt that it can be done after a while of
researching and testing. You could do it with Userforms though, is that an
option ?
 
G

Guest

No - I need it to work ith users still using XL 95. i appreciate that it
can be done in UserForms, but the solution must support xl 95.

Cheers
Romulus
 
T

Tom Ogilvy

Since dialog sheet are persistent in retaining values. set it up like this

Public bFlag As Boolean
Sub showDialog()
bFlag = True
Do While bFlag
DialogSheets(1).Show
Loop
End Sub

Sub Cancel_Button()
' MsgBox "In cancel"
If ActiveDialog.CheckBoxes(1) = xlOff Then
bFlag = False
End If
End Sub

the cancel_button code is assigned to the cancel key.


If you have an init event or if you clear values in your code, use the bflag
value there to see whether to clear or not.

In the above, as long as checkbox 1 is checked, the dialog is reshown.
There is an annoying flicker, but maybe that will disuade use of the escape
key.

--
Regards,
Tom Ogilvy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top