ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   DIsabling Escape Key while dialog active (https://www.excelbanter.com/excel-programming/282688-disabling-escape-key-while-dialog-active.html)

Romulus

DIsabling Escape Key while dialog active
 
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

Harald Staff

DIsabling Escape Key while dialog active
 
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 ?

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Romulus" wrote in message
...
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




Tom Ogilvy

DIsabling Escape Key while dialog active
 
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.

--
Regards,
Tom Ogilvy


Romulus wrote in message
...
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




Adiv[_2_]

DIsabling Escape Key while dialog active
 

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

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com


Tom Ogilvy

DIsabling Escape Key while dialog active
 
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.

--
Regards,
Tom Ogilvy


Adiv wrote in message
...

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 Unload
event:

Application.OnKey "{ESCAPE}"

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

Hope this helps. :cool:


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/




Romulus

DIsabling Escape Key while dialog active
 
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?

-----Original Message-----
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
.


Harald Staff

DIsabling Escape Key while dialog active
 
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 ?
--
HTH. Best wishes Harald
Followup to newsgroup only please


"Romulus" skrev i melding
...
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?




No Name

DIsabling Escape Key while dialog active
 
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
"Harald Staff" wrote in message
...
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 ?
--
HTH. Best wishes Harald
Followup to newsgroup only please


"Romulus" skrev i melding
...
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?






Tom Ogilvy

DIsabling Escape Key while dialog active
 
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





<Romu wrote in message ...
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
"Harald Staff" wrote in message
...
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 ?
--
HTH. Best wishes Harald
Followup to newsgroup only please


"Romulus" skrev i melding
...
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?









All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com