Hi folks. Two questions, rather related. I have a userform with a textbox, a checkbox, a combobox, and two commandbuttons.
One commandbutton just unloads the form, this can be ignored.
The other commandbutton clears the other controls.
The textbox goes to "".
The checkbox becomes unchecked.
The combobox goes back to ListIndex = 0. here is the code:
Nothing unusual about it. Except for this.
With IntelliSense when I type "TypeOf ctl Is" I get lots of choices, including Textbox, CheckBox, and ComboBox. Fine, this is as it should be. But the instructions for the checkbox NEVER fire. I am sure it something stupid, but what?
Second question. How do you get a string of an identifier? I thought I would get a Debug.Print of TypeOf itself. I can not seem to do so.
Thanks.
Gerry
My paintings and sculpture
One commandbutton just unloads the form, this can be ignored.
The other commandbutton clears the other controls.
The textbox goes to "".
The checkbox becomes unchecked.
The combobox goes back to ListIndex = 0. here is the code:
Code:
Sub CommandButton2_Click()
Dim ctl As Control
For Each ctl In Me.Controls
Debug.Print ctl.Name
[COLOR=red]' This will print "Checkbox1"
' when it gets to the checkbox[/color red]
If TypeOf ctl Is TextBox Then
[COLOR=red]' This will works fine[/color red]
Debug.Print ctl.Name
Me.Controls(ctl.Name).Text = ""
ElseIf TypeOf ctl Is CheckBox Then
[COLOR=red]Debug.Print ctl.Name ' this does NOT
Me.Controls(ctl.Name).Value = False[/color red]
ElseIf TypeOf ctl Is ComboBox Then
[COLOR=red]' This will works fine[/color red]
Debug.Print ctl.Name
Me.Controls(ctl.Name).ListIndex = 0
End If
Next
End Sub
With IntelliSense when I type "TypeOf ctl Is" I get lots of choices, including Textbox, CheckBox, and ComboBox. Fine, this is as it should be. But the instructions for the checkbox NEVER fire. I am sure it something stupid, but what?
Second question. How do you get a string of an identifier? I thought I would get a Debug.Print of TypeOf itself. I can not seem to do so.
Thanks.
Gerry
My paintings and sculpture