Usage of Enter Key

Wolfryder88

New member
Local time
Today, 15:32
Joined
Dec 27, 2002
Messages
6
I have a continuous form with an unbound text box (for search critera) and a command button to kick off the search, which simply applies a filter.

When a user enters text in the unbound text box and hits "Enter", I want the search to be kicked off (instead of having to tab over or mouse over to click the "Search" command button. This is the default functionality of an HTML <form>, so users kind of expect it. But I'm having trouble implementing it in MsAccess.

I've tried using the KeyDown property of the unbound textbox, but no luck, since the KeyDown method occurs before the data in the box is saved. I'm guessing this is related to detecting what key has been pressed but my issue seems to be the order of events occurring on the form.

Any suggestions? This *must* be common situation, but I've found no related topics in searching the forum.
 
I'm getting closer to solving my puzzle. Using Keyup works (since it occurs after the Change event?). Now I'm stuck with a loop if there are no search results, since a message box appears to tell the user such, and entering thru the message box triggers the Keyup . . oops). But this will easy enough to fix.

However, if there's a better solution I'd love to know.
 
Use the LosFocus event to trigger your search. This will only cause the search to be triggered when the focus is moved from the text box. Make sure to write some safety measure so that it the text box is Empty the search is not triggered.
ie:
If TextBox.value = "" Then
Else
Run the Search
End If

If isNull(TextBox.value) Then
Else
Run your Search
End If

Private Sub Text0_LostFocus()
MsgBox "The Enter Key was pressed"
End Sub
 
Access allows for one button on a form to be the "Default" button and hitting <enter> on the form causes that button to be pressed. Set the "Default" property of the button to True. Find this property on the "Other" tab of a button's property sheet.
 

Users who are viewing this thread

Back
Top Bottom