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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

link a button to a text box 1

Status
Not open for further replies.

Stuartp

Technical User
Feb 22, 2001
178
0
0
GB
How can I link a button to a text box on a form so that the user can type something into the text box and then press the Enter key on the keyboard and it will execute the code behind the button as if the user had clicked the button with a mouse.

I know I can assign shortcuts to buttons like Ctrl-A or whatever, but the Enter key would be more convenient espeically for application using search features.

Thanks,

Stuart
 
Your code would look something like this, to execute a command button after some text has been entered into a text box:

Private Sub Command1_Click()
' do something
MsgBox "Hello"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'if enter key is pressed
Call Command1_Click
End If
End Sub
 
You could also just set that button's default property to TRUE and it will work also.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top