Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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!
0
igfp
Asked:
igfp
  • 3
1 Solution
 
trkcorpCommented:
Set the Default property of the button you want to execute on enter to True.
0
 
trkcorpCommented:
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
0
 
YaakovSCommented:
setting the cancel property to true will activate it's click event when the user presses Esc.
0
 
trkcorpCommented:
OOPS! YaakovS is correct!
0
 
igfpAuthor Commented:
Thank man! Points go to you as you were the first to do this! I apreciate both helps. Life savers!!! :p
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now