BrianExcel
Well-known Member
- Joined
- Apr 21, 2010
- Messages
- 975
I am running the following code for a userform when I press the "enter" key...
Right now, within the btnCenterlookup_Click there is a line of code at the end that tries to reset focus to the textbox referenced above (txtcenternumber.setfocus).
But, it's like that line of code doesn't run when I press the button. Everything else works fine, but the focus moves to the next control (within a frame) instead of staying on the textbox indicated above.
Basically, I want the focus ALWAYS to be set to that textbox unless the user physically goes somewhere else via mouse.
Any thoughts on why the .setfocus property isn't working?
Code:
Sub txtCenterNumber_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal shift As Integer)
Application.ScreenUpdating = False
If KeyCode = vbKeyReturn Then
btnCenterLookup_Click
End If
End Sub
Right now, within the btnCenterlookup_Click there is a line of code at the end that tries to reset focus to the textbox referenced above (txtcenternumber.setfocus).
But, it's like that line of code doesn't run when I press the button. Everything else works fine, but the focus moves to the next control (within a frame) instead of staying on the textbox indicated above.
Basically, I want the focus ALWAYS to be set to that textbox unless the user physically goes somewhere else via mouse.
Any thoughts on why the .setfocus property isn't working?