Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Automatically detect Enter Key

Automatically detect Enter Key

Automatically detect Enter Key

I have a form with a text box in and a command button.

At the moment a user types something in the text box and then clicks the button.

is there a way that rather than having to click the button I can automatically detect if the enter key has been pressed, and then do the command button ?

RE: Automatically detect Enter Key

Please read point #16 in FAQ222-2244: How to get the best answers as this is important now that you have asked over a dozen questions.

To answer your question, set the button's "Default" property to "True"

RE: Automatically detect Enter Key

Thank you for your reply

I've managed to achieve what I wanted by useing

Private Sub txtURN_KeyPress(KeyAscii As Integer)
    If (KeyAscii = 13) Then
    Call cmdURNSearch_Click
    End If
End Sub


RE: Automatically detect Enter Key

That will work but would only be needed if the text box is Multi-Line or there is another command button which has it's "Default" setting to "True", or if the command button should react only when the focus is on the text box, otherwise not.

RE: Automatically detect Enter Key

To give a little more information to SB's post, the "Default" property may be set for one and only one command button, and pressing the Enter key will be equivalent to pressing that button.  The "Cancel" property may be set also to one and only one Command button, and pressing the Escape key will be equivalent to pressing that button.

If you set the default property to true for a command button, the Keypress event has no effect where the enter key is concerned, for the Default property overrides it.

If I wanted each text box to treat the enter key differently for some reason, I would organize the text boxes into an array.  I would then call a procedure from the click event of the command button, passing the index property of the current text box as an argument.



RE: Automatically detect Enter Key

Is it possible that you are looking for the AfterUpdate event?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close