View Full Version : Solved: Userform query
blackie42
10-29-2008, 08:13 AM
Hi
Was wondering if its possible to automatically skip to the next textbox on the userform once 2 numbers have been entered. I suspect I need to limit the length to 2 characters and then only allow numbers in the textbox.
Can anyone help with limiting the TB to numbers and also the auto skip once to numbers are entered?
thanks in advance
Jon
fb7894
10-29-2008, 08:23 AM
Private Sub TextBox1_Change()
If Len(TextBox1) = 2 Then
TextBox2.SetFocus
End If
End Sub
blackie42
10-29-2008, 08:48 AM
Thanks - skip bit works well
Any ideas about only allowing numeric values only at the same time e.g.
user gets message if inputs anything that isn't numeric
thanks again
RonMcK
10-29-2008, 10:21 AM
Blackie,
You might try:Private Sub TextBox1_Change()
If Not IsNumeric(Textbox1) Then
MsgBox ("You must enter a numeric. Please Try again.")
Textbox1.Value = ""
Textbox1.SetFocus
End Sub
End If
If Len(Textbox1) = 2 Then
TextBox2.SetFocus
End If
End Sub
blackie42
10-29-2008, 12:14 PM
Hi - thanks for reply
Will give it a try tomorrow
regards
Greetings Blackie:
You could also use the textbox's provided properties, as to AutoTab and MaxLength; either in Intitialize or Activate, or simply in the properties window during design.
Private Sub UserForm_Initialize()
With Me.TextBox1
.AutoTab = True
.MaxLength = 2
End With
End Sub
...A small tweak to Ron's, to prevent the MsgBox from popping back up when the value gets emptied.
Private Sub TextBox1_Change()
If Not IsNumeric(TextBox1) _
And Not TextBox1.Value = "" Then
MsgBox ("You must enter a numeric. Please Try again.")
TextBox1.Value = ""
TextBox1.SetFocus
End If
End Sub
Hope this helps,
Mark
blackie42
10-30-2008, 05:47 AM
Again - works fine - thanks for help
regards
Jon
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.