Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accelerator key - special keys 1

Status
Not open for further replies.

venkman

Programmer
Oct 9, 2001
467
US
How do I assign a non alpha-numeric key as an accelerator for a control. For instance I want the escape key to activate a button control.
Thanks,
Venkman
 
venkman:

The following code will run the sub RUNTHIS whenever the escape key is pressed.
Code:
  Application.OnKey "{ESCAPE}", "RUNTHIS"
Regards, LoNeRaVeR
 
The following will assign the click event of a button on sheet 1.

Application.OnKey "{ESC}", "Sheet1.CommandButton1_Click"

This should cause Pressing Esc to have the same effect of clicking on the button. You can assign any macro to a Key using OnKey, in the same manner.

A.C.
 
Sorry, I wasn't clear enough before. The button is on a form. How do I make the above work for just when this form is loaded?

-Venkman
 
For the specific case of the escape key and a button on a form, set the .cancel property of the button to true - this will make the escape key activate it. Only one button on a form can have this property set.
Rob
[flowerface]
 
Thanks Rob, was what I was looking for.
-Venkman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top