buttons and boxes in userform

L

Larry Sartoris

Hi,

I was wondering if there was a way to automatically change to a different
text box after entering only one number. I know if you have multiple text
boxes then you can enter info and then hit tab to switch to the next box.
What I want to do is only enter one number into a text box and then have it
move on to the next box.

Thanks so much for any help.

Larry
 
A

Anita

Hi Larry,

Try something like this:

Private Sub TextBox1_Change()
TextBox2.SetFocus
End Sub

For any change to the text in textbox1, textbox2 gets the focus.
 
L

Larry Sartoris

Thanks so much for your reply and help. I just have one more question. That
worked beautifully, but what if I wanted to enter 2 numbers into the textbox?

Thanks so much!
 
A

Anita

You can trigger it to switch after whatever number of numbers have been
typed in, for example:

Private Sub TextBox1_Change()
If Me.TextBox1.TextLength = 1 Then Exit Sub
If Me.TextBox1.TextLength = 2 Then Me.TextBox2.SetFocus
End Sub

Will switch after two numbers have been typed in. You can use this
logic to set it to whatever number you want by setting the TextLength =
?

Anita
 
Top