Key Down Event and Query by Forms not working together!

  • Thread starter Thread starter Joe S Slow
  • Start date Start date
J

Joe S Slow

I have built a search form that has an unbound text field and a command
button. When the command button is pressed whatever is in the unbound text
field is used by the query to search by.

The thing I thought would be neat would be to have the query run as soon as
I hit the Enter key instead of clicking the Search button.

I have programmed it in the text field on the event 'On Key Down' with the
following code:

If KeyCode = vbKeyReturn Then
DoCmd.OpenForm stDocName, , , stLinkCriteria
'KeyCode = 0 'Do this to prevent the
default action for the key
End If

The problem is that as soon as I hit the Enter key the query that runs looks
up the search text field but unfortunately it doesn't see anything in the
field. Usually when I click on the submit button I guess whatever I typed in
the search txt field is 'registered' so when the query by form looks up the
field something actually exists. With my 'On Key Down' event it looks like
this field was not entered and terminated prematurely so when the query
looks up the table it doesn't find anything.

Is there any command that I can issue so that whatever I typed prior to
hitting the Enter key is registered so when the query by form happens that
the field will be been populated.

Thanks!
 
Joe,

Move your OpenForm code to the AfterUpdate event of the
textbox. This will fire when the Enter key is pressed and
you won't have any need for the KeyPress code.

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
That works! thanks!

Gary Miller said:
Joe,

Move your OpenForm code to the AfterUpdate event of the
textbox. This will fire when the Enter key is pressed and
you won't have any need for the KeyPress code.

--

Gary Miller
Gary Miller Computer Services
Sisters, OR
________________________
 
Back
Top