BrianExcel
Well-known Member
- Joined
- Apr 21, 2010
- Messages
- 975
I have a text box on a userform in which the user enters a 4-digit number and then presses 'Enter.' When the user presses enter the following code runs:
My problem is that the .setfocus command doesn't work. When the user hits enter, I don't need to erase the current value in the text box, but I basically want whatever 4-digit number the user enters next to overwrite the current one so the user can just enter a number and then press enter, enter another number, press enter again, etc.
What am I doing wrong?
PS - The btnCenterLookup_Click runs more code, but rather than having a button AND the enter code, which would require the same code twice, I wanted them to just press enter, so I left the button as not visible.
Code:
Private Sub txtCenter_Change()
Application.ScreenUpdating = False
If KeyCode = vbKeyReturn Then
btnCenterLookup_Click
frmCenterLookup.txtCenter.SetFocus
End If
End Sub
My problem is that the .setfocus command doesn't work. When the user hits enter, I don't need to erase the current value in the text box, but I basically want whatever 4-digit number the user enters next to overwrite the current one so the user can just enter a number and then press enter, enter another number, press enter again, etc.
What am I doing wrong?
PS - The btnCenterLookup_Click runs more code, but rather than having a button AND the enter code, which would require the same code twice, I wanted them to just press enter, so I left the button as not visible.