Keydown question

A

alex

Keydown question

I have some code in the keydown event of a textbox control:

Private Sub txtSearch_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 And Shift = 0 Then
' The Enter key was pressed
Call cmdSearch_Click
End If
End Sub

When the enter key is pressed the sub calls another procedure that
checks to see if txtSearch has a value and returns a msgbox or runs
more code.

I have two small issues with this code…
1. The value in txtSearch is not being saved prior to the key down
event, so the textbox always appears empty. I was setting the focus
away from the textbox prior to calling cmdSearch_Click, but I assume
there’s a way to save the value in a textbox without setting the focus
elsewhere.

2. After the key down event, and subsequently calling the
cmdSearch_Click event, I cannot set the focus back to the textbox (for
example if it’s truly null, focus should be sent back to txtSearch).
What happens is the focus moves to the next tab control regardless of
my futile coding attempts.

Any thoughts?
Thanks,
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Trapping Enter Key No Longer Working 4
ListView in Access 2007 0
Working with Filters 0
Form_KeyDown(): Not Firing? 2
SetFocus Not working 4
Record Search within a Form 3
Trapping Edit Mode ! 11
Keydown Problem 4

Top