We help IT Professionals succeed at work.

Code to move cursor from Textbox1 to another Textbox in a userform.

I have a userform which is using code that places a date in a textbox this working well.
I would like to continue the code to then move the cursor to another textbox ready to receive typed in data.
Can someome help please.
Comment
Watch Question

Commented:
Private Sub txtData_AfterUpdate()
    txtData = Format(txtData, "Short Date")
    txtSequencia.SetFocus
End Sub
Most Valuable Expert 2012
Top Expert 2012
Commented:
I would consider setting the tabIndex on all your controls in the userform to the logical sequence.  E.g., start with the control at the top left, change its tabIndex to 0, then the next to 1, all the way down to the last control button OK or Cancel, for example.  You'll find that the userform design lends itself to the sequencing of user input.

I would wait until the userform design is complete to do this, as the underlying editor messes with the tab Index as you add controls, but stabilizes once you're done, then you can set the index (order of navigation) at one time.

Generally, the index is set as you create controls, but then gets messed up quickly when you copy/paste, move them around, etc., for understandable reasons.

Cheers,

Dave

Author

Commented:
I have installed to code provided it works find except. The new problem is after I "SAVE" the record from the userform. On starting a new record the code stalls when I reset the focus back to TextBox1 instead of TextBox2 as requested is there a simple solution.
Should I dis-enable TextBox2 firstly.
I have used the code below.

The line of code:    Me.TextBox1.SetFocus

Thanks for the code in the first comment.

Author

Commented:
Thanks for both solutions The advice was appreciated. I'll need to re-evaluate my question to find the final answer to my questions.

Thanks for your efforts.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.