Hi all. I've found many threads on this topic, but most of them are forcefully shut down by someone insisting that the OP give up and use default buttons. This is not the right option for me, so please don't suggest it.
I have a search box (unbound text box) and, next to it, a search button. The search button checks whether the search box is blank or null, and if it's not, it searches the form's table--if it finds no match, a message box pops up and says so; if it finds a match, it filters the form to that record.
When the user hits the Enter key in the search box, I want it to click the search button. I'm using this code:
I also changed the Enter Key Behavior property of the text box to "New Line in Field" rather than Default, since Default just moves to the next control in the tab order (even with the KeyAscii = 0 line, which seems necessary to prevent hitting Enter from actually inputting a new line before the search is executed).
If I hit Enter twice, it works, but I have to hit it twice. If I hit it once, it just highlights the string in the text box. What is going wrong?
Attaching a sample database.
I have a search box (unbound text box) and, next to it, a search button. The search button checks whether the search box is blank or null, and if it's not, it searches the form's table--if it finds no match, a message box pops up and says so; if it finds a match, it filters the form to that record.
When the user hits the Enter key in the search box, I want it to click the search button. I'm using this code:
Code:
Private Sub SearchText_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'Enter key
KeyAscii = 0
Call SearchButton_Click
End If
End Sub
I also changed the Enter Key Behavior property of the text box to "New Line in Field" rather than Default, since Default just moves to the next control in the tab order (even with the KeyAscii = 0 line, which seems necessary to prevent hitting Enter from actually inputting a new line before the search is executed).
If I hit Enter twice, it works, but I have to hit it twice. If I hit it once, it just highlights the string in the text box. What is going wrong?
Attaching a sample database.
Attachments
Last edited: