How to do an "on enter" event (1 Viewer)

darkmastergyz

Registered User.
Local time
Yesterday, 22:12
Joined
May 7, 2006
Messages
85
I have a form right now, where I do a filter-based search. I'd like to press enter to do a search, but I'm not sure how to do that. Now my filter is triggered by a button push. How can I change it to enter? Thanks.
 

Fernando

Registered User.
Local time
Today, 01:12
Joined
Feb 9, 2007
Messages
89
u can use the KeyPress event. Lets say you press enter when u finished to input data on the search textbox (txtSearch). Having that your button is called cmdSearch,
Code:
Private Sub txSearch_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then 'Enter key
        Call cmdSearch_Click
    End If
End Sub
 

Fernando

Registered User.
Local time
Today, 01:12
Joined
Feb 9, 2007
Messages
89
O i forgot, you have to change txtSearch properties:
On Other tab
Enter Key Behavior: New Line in Field
GL
 

missinglinq

AWF VIP
Local time
Today, 01:12
Joined
Jun 20, 2003
Messages
6,423
FYI, the "OnEnter" event has nothing to do with the <Enter> key! This event deals with "entering" a textbox or combobox and immediately preceeds the GotFocus event.
 

boblarson

Smeghead
Local time
Yesterday, 22:12
Joined
Jan 12, 2001
Messages
32,059
If you want to press your enter key and have it act as though you pressed the command button, just set the command button's DEFAULT property to YES. You can only have one default command button on a form. If you set the default property to yes then anytime, from anywhere while you are on that form and you press the enter key then it will trigger the click event for that button.

You can also use the Escape key in the same way. All you need to do is set the command button's Cancel property to YES to get that button's click event to fire when the escape key is pressed.
 

Fernando

Registered User.
Local time
Today, 01:12
Joined
Feb 9, 2007
Messages
89
If you want to press your enter key and have it act as though you pressed the command button, just set the command button's DEFAULT property to YES. You can only have one default command button on a form. If you set the default property to yes then anytime, from anywhere while you are on that form and you press the enter key then it will trigger the click event for that button.

You can also use the Escape key in the same way. All you need to do is set the command button's Cancel property to YES to get that button's click event to fire when the escape key is pressed.


Nice i didnt know that, thx
 

missinglinq

AWF VIP
Local time
Today, 01:12
Joined
Jun 20, 2003
Messages
6,423
If you set the default property to yes then anytime, from anywhere while you are on that form and you press the enter key then it will trigger the click event for that button.
That's not exactly true, Bob! It's true if you're on a textbox, say, but if you're on another command button and hit <Enter> that button's code runs, not the code for the button with Default set to Yes!
 

boblarson

Smeghead
Local time
Yesterday, 22:12
Joined
Jan 12, 2001
Messages
32,059
Okay, that's true and I should have phrased that slightly differently. I wasn't thinking about command buttons when I wrote that, I was thinking of Text boxes, check boxes, list boxes, combo boxes, etc.; anywhere where you would normally do that. But, you are correct, I didn't state that and so my statement was inaccurate.
 

Users who are viewing this thread

Top Bottom