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!

When hitting "Enter" on a text box, how do I make it execute a command

Status
Not open for further replies.

mark01

Technical User
Jan 17, 2001
600
US
I have a text box, with an OK, and a Cancel Button. I want it to execute the OK when I hit enter after typing in text on the text box. How would I do that?

 
If I understand what you are saying correctly set focus to the save cmd after the edit. You may have to play around with got focus and lost focus on the text box to do it.
 
This is what I have:

Private Sub Text1_LostFocus()
Call Command1_Click
End Sub

This doesn't work for me :)
 
How about setting the Default property of the 'OK' button to true?

-dave
 
The simplest way to do this is using the KeyPress event:

Code:
Private Sub txtYourTextbox_KeyPress(KeyAscii as Integer)
    If (KeyAscii = vbKeyReturn) Then 'ENTER key is pressed
        Call cmdYourCommandButton_Click()
    End If
End Sub
 
Awesome, thats exactly what I needed. I am a little slow. :) Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top