Adding controls to userform

E

ExcelMonkey

I have a userform with checkboxes. As the form and
routine progress in the development phase, I want to
program in an efficient manner so that I can add the new
controls as quickly and efficiently as possible. The
check boxes are are independent. There are 7 of them.
Number 7 is a "Select All" checkbox. Now when I decide to
add another checkbox (chckbx8). I will, based on this
code, have to create:
1) a new click event for chckbx8
2) edit the click event in checkbox7 (select all chkbox)
to incorporate chckbx8

If there a more efficient way to code this knowing that I
will be adding checkboxes gong forward? Or is this the
best way to do it?

Private Sub CheckBox1_Click()
If CheckBox1 = False Then
CheckBox7 = False
End If
End Sub

Private Sub CheckBox2_Click()
If CheckBox2 = False Then
CheckBox7 = False
End If
End Sub

Private Sub CheckBox3_Click()
If CheckBox3 = False Then
CheckBox7 = False
End If
End Sub

Private Sub CheckBox4_Click()
If CheckBox5 = False Then
CheckBox7 = False
End If
End Sub

Private Sub CheckBox5_Click()
If CheckBox6 = False Then
CheckBox7 = False
End If
End Sub

Private Sub CheckBox6_Click()
If CheckBox6 = True Then
CheckBox1 = True
CheckBox2 = True
CheckBox3 = True
CheckBox4 = True
CheckBox5 = True
End If

If CheckBox6 = False Then
CheckBox1 = False
CheckBox2 = False
CheckBox3 = False
CheckBox4 = False
CheckBox5 = False
End If
End Sub
 
B

Bob Phillips

Here is a bit

Private Sub CheckBox1_Click()
Check_Checkbox7 CheckBox1
End Sub

Private Sub CheckBox2_Click()
Check_Checkbox7 CheckBox2
End Sub

Private Sub CheckBox3_Click()
Check_Checkbox7 CheckBox3
End Sub

Private Sub Check_Checkbox7(checkbox As MSForms.checkbox)
If checkbox = False Then
CheckBox7 = False
End If
End Sub

Private Sub CheckBox4_Click()
Check_Checkbox7 CheckBox4
End Sub

Private Sub CheckBox5_Click()
Check_Checkbox7 CheckBox5
End Sub

Private Sub CheckBox6_Click()
Dim i As Long
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Name <> "CheckBox7" And ctl.Name <> "CheckBox6" Then
ctl.Value = CheckBox6.Value
End If
End If
Next ctl
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)
 
E

ExcelMonkey

Thanks Bob!
-----Original Message-----
Here is a bit

Private Sub CheckBox1_Click()
Check_Checkbox7 CheckBox1
End Sub

Private Sub CheckBox2_Click()
Check_Checkbox7 CheckBox2
End Sub

Private Sub CheckBox3_Click()
Check_Checkbox7 CheckBox3
End Sub

Private Sub Check_Checkbox7(checkbox As MSForms.checkbox)
If checkbox = False Then
CheckBox7 = False
End If
End Sub

Private Sub CheckBox4_Click()
Check_Checkbox7 CheckBox4
End Sub

Private Sub CheckBox5_Click()
Check_Checkbox7 CheckBox5
End Sub

Private Sub CheckBox6_Click()
Dim i As Long
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Name <> "CheckBox7" And ctl.Name
 
T

Tushar Mehta

Two points.

(1) You may also want to check John Walkenbach's http://j-
walk.com/ss/excel/tips/tip44.htm

(2) While leaving out a reference to an object's default property is
usually OK, it has been known to cause problems -- and is not
acceptable in the .Net world. If I were you, I'd use Checkbox{n}.Value

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top