G
Garry Jones
I have a problem with Tab Stop.
I have 5 textboxes which must be used in order.
UserForm1 starts with Textbox1, Textbox2 Enabled=True and Textbox3 thru
Textbox5 Enabled=False
After a tab from Textbox1 to Textbox2 the code sets Enabled=False for
Textbox1 and Enabled=True for Textbox3 and the cursor should now be in
Textbox2.
This does not work, the cursor skips the entire list of textboxes one by
one as if Tabstop has been turned off.
However, if I choose not to set Enabled=False for the current textbox it
works.
For other reasons not explained here I need to use Textbox_Exit for each
Textbox. I stopped an earlier problem by disabling events when running
the Enabled=False.
Bottom Line, what is wrong with the code? Why isn't it tab stopping?
_______________________________
Dim bDisableEvents As Boolean 'needed to trap enabled = true
_______________________________
Private Sub UserForm_Initialize()
'user must use textboxes in order
'3 textboxes swicthed off with this
TextBox3.Enabled = False 'switch off textbox3
TextBox4.Enabled = False 'switch off textbox3
TextBox5.Enabled = False 'switch off textbox3
End Sub
_______________________________
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (1)
End Sub
_______________________________
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (2)
End Sub
_______________________________
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (3)
End Sub
_______________________________
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (4)
End Sub
_______________________________
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (5)
End Sub
_______________________________
Private Sub ntl(bnum As Integer)
'This disables the current textbox
With UserForm1("textbox" & bnum)
bDisableEvents = True
.Enabled = False 'offending code
bDisableEvents = False
End With
'This enables the text box two after current
Dim bbbnum As Integer
bbbnum = bnum + 2
If bbbnum < 6 Then
With UserForm1("textbox" & bbbnum)
.Enabled = True
End With
End If
End Sub
_______________________________
Note:
If I comment out the offending code it works except for the fact that
the Textboxes that should be Enabled=False are still Enabled = True.
If anyone can help me I will be grateful. If you want to see it in
action create a userform with 5 textboxes. Change the offending code to
"comment" and it will tab, remove comment and it will skip textboxes.
Why?
Garry Jones
Sweden
I have 5 textboxes which must be used in order.
UserForm1 starts with Textbox1, Textbox2 Enabled=True and Textbox3 thru
Textbox5 Enabled=False
After a tab from Textbox1 to Textbox2 the code sets Enabled=False for
Textbox1 and Enabled=True for Textbox3 and the cursor should now be in
Textbox2.
This does not work, the cursor skips the entire list of textboxes one by
one as if Tabstop has been turned off.
However, if I choose not to set Enabled=False for the current textbox it
works.
For other reasons not explained here I need to use Textbox_Exit for each
Textbox. I stopped an earlier problem by disabling events when running
the Enabled=False.
Bottom Line, what is wrong with the code? Why isn't it tab stopping?
_______________________________
Dim bDisableEvents As Boolean 'needed to trap enabled = true
_______________________________
Private Sub UserForm_Initialize()
'user must use textboxes in order
'3 textboxes swicthed off with this
TextBox3.Enabled = False 'switch off textbox3
TextBox4.Enabled = False 'switch off textbox3
TextBox5.Enabled = False 'switch off textbox3
End Sub
_______________________________
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (1)
End Sub
_______________________________
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (2)
End Sub
_______________________________
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (3)
End Sub
_______________________________
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (4)
End Sub
_______________________________
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If bDisableEvents Then Exit Sub
ntl (5)
End Sub
_______________________________
Private Sub ntl(bnum As Integer)
'This disables the current textbox
With UserForm1("textbox" & bnum)
bDisableEvents = True
.Enabled = False 'offending code
bDisableEvents = False
End With
'This enables the text box two after current
Dim bbbnum As Integer
bbbnum = bnum + 2
If bbbnum < 6 Then
With UserForm1("textbox" & bbbnum)
.Enabled = True
End With
End If
End Sub
_______________________________
Note:
If I comment out the offending code it works except for the fact that
the Textboxes that should be Enabled=False are still Enabled = True.
If anyone can help me I will be grateful. If you want to see it in
action create a userform with 5 textboxes. Change the offending code to
"comment" and it will tab, remove comment and it will skip textboxes.
Why?
Garry Jones
Sweden