Link to home
Start Free TrialLog in
Avatar of igfp
igfp

asked on

Esc and Enter in Form

I have a form with 2 command buttons. One is cancel, and one is ok. I have many text boxes for the user to input. When user presses 'Enter' I want it to go like "ok" and if user presses 'Esc' I want it to make as "Cancel". Any help?

Thanks everyone!
ASKER CERTIFIED SOLUTION
Avatar of trkcorp
trkcorp

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trkcorp
trkcorp

As for the Esc portion, you could set the KeyPreview property = True on the FORM and when the user presses Esc execute the button's click event. Like:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then cmd_Click
End Sub
setting the cancel property to true will activate it's click event when the user presses Esc.
OOPS! YaakovS is correct!
Avatar of igfp

ASKER

Thank man! Points go to you as you were the first to do this! I apreciate both helps. Life savers!!! :p