Togglebutton to change Checkboxes

C

Corey

I am trying to get a toggle button when pressed to tick ALL checkboxes(17) on a form, but cannot get
it to change them.

I am using:

Private Sub ToggleButton1_Click()
If ToggleButton1 Then
CheckBox1 = True And CheckBox2 = True And CheckBox3 = True And CheckBox4 = True And CheckBox5 = True
And CheckBox6 = True And _
CheckBox7 = True And CheckBox8 = True And CheckBox9 = True And CheckBox10 = True And CheckBox11 =
True And CheckBox12 = True And _
CheckBox13 = True And CheckBox14 = True And CheckBox15 = True And CheckBox16 = True And CheckBox17
= True
Else
CheckBox1 = False And CheckBox2 = False And CheckBox3 = False And CheckBox4 = False And CheckBox5 =
False And CheckBox6 = False And _
CheckBox7 = False And CheckBox8 = False And CheckBox9 = False And CheckBox10 = False And CheckBox11
= False And CheckBox12 = False And _
CheckBox13 = False And CheckBox14 = False And CheckBox15 = False And CheckBox16 = False And
CheckBox17 = False
End If
End Sub


WHY does it not work?

Corey....
 
C

Corey

I also tried the :
If togglebutton1=true then
and the
If togglebutton1.value = True

to no avail....



I am trying to get a toggle button when pressed to tick ALL checkboxes(17) on a form, but cannot get
it to change them.

I am using:

Private Sub ToggleButton1_Click()
If ToggleButton1 Then
CheckBox1 = True And CheckBox2 = True And CheckBox3 = True And CheckBox4 = True And CheckBox5 = True
And CheckBox6 = True And _
CheckBox7 = True And CheckBox8 = True And CheckBox9 = True And CheckBox10 = True And CheckBox11 =
True And CheckBox12 = True And _
CheckBox13 = True And CheckBox14 = True And CheckBox15 = True And CheckBox16 = True And CheckBox17
= True
Else
CheckBox1 = False And CheckBox2 = False And CheckBox3 = False And CheckBox4 = False And CheckBox5 =
False And CheckBox6 = False And _
CheckBox7 = False And CheckBox8 = False And CheckBox9 = False And CheckBox10 = False And CheckBox11
= False And CheckBox12 = False And _
CheckBox13 = False And CheckBox14 = False And CheckBox15 = False And CheckBox16 = False And
CheckBox17 = False
End If
End Sub


WHY does it not work?

Corey....
 
C

Corey

Got it,
It did not like the And

Private Sub ToggleButton1_Click()
If ToggleButton1 = True Then
ToggleButton2 = False
CheckBox1 = True
CheckBox2 = True
CheckBox3 = True
CheckBox4 = True
CheckBox5 = True
CheckBox6 = True
......
CheckBox17 = True
else
CheckBox1 = False
CheckBox2 = False
CheckBox3 = False
CheckBox4 = False
CheckBox5 = False
CheckBox6 = False
......
CheckBox17 = False
End If
End Sub

Corey...

I am trying to get a toggle button when pressed to tick ALL checkboxes(17) on a form, but cannot get
it to change them.

I am using:

Private Sub ToggleButton1_Click()
If ToggleButton1 Then
CheckBox1 = True And CheckBox2 = True And CheckBox3 = True And CheckBox4 = True And CheckBox5 = True
And CheckBox6 = True And _
CheckBox7 = True And CheckBox8 = True And CheckBox9 = True And CheckBox10 = True And CheckBox11 =
True And CheckBox12 = True And _
CheckBox13 = True And CheckBox14 = True And CheckBox15 = True And CheckBox16 = True And CheckBox17
= True
Else
CheckBox1 = False And CheckBox2 = False And CheckBox3 = False And CheckBox4 = False And CheckBox5 =
False And CheckBox6 = False And _
CheckBox7 = False And CheckBox8 = False And CheckBox9 = False And CheckBox10 = False And CheckBox11
= False And CheckBox12 = False And _
CheckBox13 = False And CheckBox14 = False And CheckBox15 = False And CheckBox16 = False And
CheckBox17 = False
End If
End Sub


WHY does it not work?

Corey....
 
G

Guest

I suggest a loop instead:

Private Sub ToggleButton1_Click()
Dim i As Integer
For i = 1 To 17
Me.Controls("CheckBox" & i).Value = ToggleButton1.Value
Next
End Sub
 

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