I have a Userform in Excel. It has 6 Textboxes, they are the only controls on the Userform with TabStop set to True.
I can tab and move through the textboxes. I cannot get SetFocus
to work on Events fired when moving between the Textboxes. I can put a CommandButton on the userform with Userform16.Textbox1.Setfocus
and it works as expected to move the focus to Textbox1.
I set up a simple test event (see below) to move the textbox focus back up to TextBox1 when Textbox2 is entered. It moves focus to Textbox3 when I tab out of TextBox1.
Private Sub TextBox2_Enter()
Cancel = True
UserForm16.TextBox1.SetFocus
End Sub
By putting a Stop
in the above, I can see that the event is firing as expected, but it will not allow me to control the focus the next control.
I get the same results with or without the Cancel = True
statement in the sub.
TextBox1
before leaving it, why dont you handle it instead inTextBox1_Exit
, by settingCancel = True
? – A.S.H