Basically I have Split Form with an unbound text box that is associated with a filter button. User will type in a value then click the filter button and everything works fine. However, I been trying to get it to where the user can also press Enter on the keyboard instead of having to click the button or of course press enter twice so that the button next to the text box gets focus and then clicks by the second Enter press. I have been messing with this for a while and did get it work eventually but its very odd. I had to repeat the VBA code twice for it to work in the KeyDown Event:
Private Sub txtFilter_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn Then
Me.txtFilter.SetFocus
Me.Filter = "[Clerk] Like '*" & Me.txtFilter & "*'"
Me.FilterOn = True
Me.Requery
Me.txtFilter.SetFocus
Me.Filter = "[Clerk] Like '*" & Me.txtFilter & "*'"
Me.FilterOn = True
Me.Requery
Me.txtFilter.SetFocus
End If
End Sub
If I don't repeat the code twice, it doesn't do the filter when I press the Enter key. Also, the Me.txtFilter.SetFocus doesn't seem to work as well. The focus still ends up on the button but I want it to end on the text box because then the user can type again without have to use the mouse or Shift Tab to go back to the box the try another search.
Any help would be appreciated into figuring out what I am doing wrong. Thanks.