-
userform - help needed
Hello to everyone.
I created a userform (UserForm1), and inside this form I placed 20 textboxes and 20 checkboxes.
Everytime I make the userform to appear, I need all the checkboxes to be false and all the listboxes to be empty
One question at a time...
I can write down 20 rows to set each checkbox value=false but I would like to have something better
I tried
Code:
For i = 1 To 20
UserForm1.Controls("CheckBox" & Chr(64 + i)).Value = False
Next i
but it says runtime error, impossible to find the specified object
These instructions are placed in the command button macro, just before the UserForm1.show line
How can I fix the error?
Thanks to everyone
-
Hi Elane, welcome to the forum.
Try as below:
Code:
Dim i As Integer
For i = 1 To 3
UserForm1.Controls("CheckBox" & i).Value = False
Next i
UserForm1.Show
Unless your checkbox's are named 'CheckBoxA', 'CheckBoxB' etc.?
-
you may also try this on the Activate event of your UserForm
Code:
Private Sub UserForm_Activate()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is TextBox Then
ctl = ""
ElseIf TypeOf ctl Is CheckBox Then
ctl = 0
End If
Next
End Sub