Hi everyone,
I am making a simple userform with a couple text boxes and 2 buttons. I am having a terrible time setting up the userform to set the focus of the cursor to my textbox after pressing enter - I want the focus set to this textbox every single time I press enter. This is my code, my userform's name is ScanningInterface. The issue is whenever I press [Enter] to submit my textbox input, the focus is shifted to one of my buttons right below it, even with all the .SetFocus commands I have!
'Whenever the userform pops up, sets focus - it works great right here
Private Sub UserForm_Activate()
ScanInput.SetFocus
End Sub
'Press enter - activate the sub Updatesheet from Module1
Private Sub ScanInput_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
ScanInput.SetFocus
If KeyCode = vbKeyReturn Then
ScanInput.SetFocus
Call Updatesheet
ScanningInterface.ScanInput.Text = ""
ScanInput.SetFocus
End If
ScanInput.SetFocus
End Sub
The focus is always shifted to selecting the button every time!!!
I am making a simple userform with a couple text boxes and 2 buttons. I am having a terrible time setting up the userform to set the focus of the cursor to my textbox after pressing enter - I want the focus set to this textbox every single time I press enter. This is my code, my userform's name is ScanningInterface. The issue is whenever I press [Enter] to submit my textbox input, the focus is shifted to one of my buttons right below it, even with all the .SetFocus commands I have!
'Whenever the userform pops up, sets focus - it works great right here
Private Sub UserForm_Activate()
ScanInput.SetFocus
End Sub
'Press enter - activate the sub Updatesheet from Module1
Private Sub ScanInput_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
ScanInput.SetFocus
If KeyCode = vbKeyReturn Then
ScanInput.SetFocus
Call Updatesheet
ScanningInterface.ScanInput.Text = ""
ScanInput.SetFocus
End If
ScanInput.SetFocus
End Sub
The focus is always shifted to selecting the button every time!!!
Last edited: