PDA

Click to See Complete Forum and Search --> : Defaulting a key to a event procedure


Gimpster
Nov 5th, 1999, 12:20 AM
I have a text box and I want to be able to program it so that when you hit the "Enter" key, it automatically runs the event procedure of a button that I also have on the form. How can I do this?

------------------
Ryan
corneslen@hotmail.com
ICQ# 47799046

Yonatan
Nov 5th, 1999, 12:27 AM
Try this:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
' Remove the word Rem from the following line, if you also want to remove text from the TextBox when Enter is pressed
Rem Text1.Text = ""
Command1.Value = True
End If
End Sub

P.S. This is post no. 9999... :)

------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)

Gimpster
Nov 5th, 1999, 12:42 AM
Thanks! It works great.

------------------
Ryan
corneslen@hotmail.com
ICQ# 47799046

Nov 5th, 1999, 01:16 AM
how about the RaiseEvent command?

RaiseEvent command1_click

or does this only work in class modules?


------------------

Wossname,
Email me: wossnamex@talk21.com :)