From: David on
I have a form with several controls.

Rather than writing code for each keypress or a single
procedure call by every controls keypress event,
what is the best way to globally trap the escape key?



From: Karl E. Peterson on
David wrote:
> I have a form with several controls.
>
> Rather than writing code for each keypress or a single
> procedure call by every controls keypress event,
> what is the best way to globally trap the escape key?

Global's a little tricky. Have you fiddled with the form's KeyPreview
property, though?

--
..NET: It's About Trust!
http://vfred.mvps.org


From: Tony Toews [MVP] on
"David" <NoWhere(a)earthlink.net> wrote:

>I have a form with several controls.
>
>Rather than writing code for each keypress or a single
>procedure call by every controls keypress event,
>what is the best way to globally trap the escape key?

Why not use the Cancel=True setting on a command button?

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
From: MikeD on


"David" <NoWhere(a)earthlink.net> wrote in message
news:OdAtbL4zKHA.4656(a)TK2MSFTNGP05.phx.gbl...
> I have a form with several controls.
>
> Rather than writing code for each keypress or a single
> procedure call by every controls keypress event,
> what is the best way to globally trap the escape key?


I'd go with Tony's suggestion (set a command button's Cancel property to
True). There are circumstances, however, where it may not suit your
purposes. You'll just need to test for those. Make this an EXTRA command
button on the form unless you've already got a button that should run this
code whenever the Escape key is pressed. Either at run-time (before the
form is shown) or design-time (I'd recommend run-time), move it way off the
form by setting its Left or Top property to something like -10000. You
can't make it invisible; otherwise, its Click event won't fire when the
Escape key is pressed.

--
Mike

P.S. If it wasn't clear, write the code you want executed when the Cancel
key is pressed in that command button's Click event. You can even run it
programmatically by setting that command button's Value property to True
(the programmatic way of "clicking" a command button).


From: David on
Thanks for input all.

Will check out solutions.

FWIW: What I had in mind was this:

I have a form
A listbox on the form
A frame
A couple textboxes on the frame
A hidden command button on the form.
----------------------------------------------------

I have a set of menu edit options on the form which will allow me
to enter edit or save mode for the textboxes. I also have a textbox edit
class which will allow undo of any given textbox.

When Edit or Add (from the menu) is selected, the command (save) button is
made visible. Rather than a cancel button -- I thought I would try using a
global "Esc" instead.

Form is exited either from menu option or X button upper right.

No one suggested a keyboard hook?

Thanks
David






"MikeD" <nobody(a)nowhere.edu> wrote in message
news:%23jruDc6zKHA.5548(a)TK2MSFTNGP06.phx.gbl...
>
>
> "David" <NoWhere(a)earthlink.net> wrote in message
> news:OdAtbL4zKHA.4656(a)TK2MSFTNGP05.phx.gbl...
>> I have a form with several controls.
>>
>> Rather than writing code for each keypress or a single
>> procedure call by every controls keypress event,
>> what is the best way to globally trap the escape key?
>
>
> I'd go with Tony's suggestion (set a command button's Cancel property to
> True). There are circumstances, however, where it may not suit your
> purposes. You'll just need to test for those. Make this an EXTRA command
> button on the form unless you've already got a button that should run this
> code whenever the Escape key is pressed. Either at run-time (before the
> form is shown) or design-time (I'd recommend run-time), move it way off
> the form by setting its Left or Top property to something like -10000.
> You can't make it invisible; otherwise, its Click event won't fire when
> the Escape key is pressed.
>
> --
> Mike
>
> P.S. If it wasn't clear, write the code you want executed when the Cancel
> key is pressed in that command button's Click event. You can even run it
> programmatically by setting that command button's Value property to True
> (the programmatic way of "clicking" a command button).
>
>