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
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