ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Togglebutton to change Checkboxes (https://www.excelbanter.com/excel-programming/392276-togglebutton-change-checkboxes.html)

Corey

Togglebutton to change Checkboxes
 
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....



Corey

Togglebutton to change Checkboxes
 
I also tried the :
If togglebutton1=true then
and the
If togglebutton1.value = True

to no avail....



"Corey" wrote in message ...
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....




Corey

Togglebutton to change Checkboxes
 
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...

"Corey" wrote in message ...
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....




Greg Wilson

Togglebutton to change Checkboxes
 
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


All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com