enable/disable start button on basis of chkbox conditions

I

ilyaskazi

I hv various chkboxes on my userform.

If any of this chkbox value is true then enable the "START" button else
disable.

Plz note: One chkbox is to select and deselect all other chkboxes. Also
if any other chkbox value

is set to false, then the chkbox(select-deselect all) becomes false.

Example file is attached with codes of selecting/deselecting all. I
required now this to reflect

accordingly to "Start" button to enable/disable.


+-------------------------------------------------------------------+
|Filename: Book3.zip |
|Download: http://www.excelforum.com/attachment.php?postid=3451 |
+-------------------------------------------------------------------+
 
B

Bob Phillips

Assuming that the button is called cmdStart

Option Explicit

Private mEnableEvents As Boolean

Private Sub CheckBox1_Click()
With Me
If mEnableEvents Then
mEnableEvents = False
mEnableEvents = False
.CheckBox2.Value = .CheckBox1.Value
.CheckBox3.Value = .CheckBox1.Value
.CheckBox4.Value = .CheckBox1.Value
.CheckBox5.Value = .CheckBox1.Value
.cmdStart.Enabled = True
mEnableEvents = True
End If
End With
End Sub

Private Sub CheckBox2_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox2
End If
End With
End Sub

Private Sub CheckBox3_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox3
End If
End With
End Sub

Private Sub CheckBox4_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox4
End If
End With
End Sub

Private Sub CheckBox5_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox5
End If
End With
End Sub

Private Sub UserForm_Activate()
mEnableEvents = True
Me.cmdStart.Enabled = False
End Sub

Private Sub SetCheckboxes(thisCb As MSForms.CheckBox)
With Me
mEnableEvents = False
If Not thisCb.Value Then
.CheckBox1.Value = False
.cmdStart.Enabled = False
ElseIf .CheckBox2.Value And .CheckBox3.Value And _
.CheckBox4.Value And .CheckBox5.Value Then
.CheckBox1.Value = True
.cmdStart.Enabled = True
End If
mEnableEvents = True
End With
End Sub
 
I

ilyaskazi

Oops, I forget to say that if other all chkboxes value is false then
dont set the cmdStart button as true.

ALL CHKBOX is FALSE then cmdStart.enabled=false

upon clicking any chkbox if other chkboxes value is true, then keep
button enable.
 
B

Bob Phillips

Option Explicit

Private mEnableEvents As Boolean

Private Sub CheckBox1_Click()
With Me
If mEnableEvents Then
mEnableEvents = False
mEnableEvents = False
.CheckBox2.Value = .CheckBox1.Value
.CheckBox3.Value = .CheckBox1.Value
.CheckBox4.Value = .CheckBox1.Value
.CheckBox5.Value = .CheckBox1.Value
If .CheckBox1.Value Then
.cmdStart.Enabled = True
End If
mEnableEvents = True
End If
End With
End Sub

Private Sub CheckBox2_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox2
End If
End With
End Sub

Private Sub CheckBox3_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox3
End If
End With
End Sub

Private Sub CheckBox4_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox4
End If
End With
End Sub

Private Sub CheckBox5_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox5
End If
End With
End Sub

Private Sub UserForm_Activate()
mEnableEvents = True
Me.cmdStart.Enabled = False
End Sub

Private Sub SetCheckboxes(thisCb As MSForms.CheckBox)
With Me
mEnableEvents = False
If Not thisCb.Value Then
.CheckBox1.Value = False
ElseIf .CheckBox2.Value And .CheckBox3.Value And _
.CheckBox4.Value And .CheckBox5.Value Then
.CheckBox1.Value = True
.cmdStart.Enabled = True
End If
If Not .CheckBox2.Value And Not .CheckBox3.Value And _
Not .CheckBox4.Value And Not .CheckBox5.Value Then
.cmdStart.Enabled = False
End If
mEnableEvents = True
End With
End Sub
 
I

ilyaskazi

no no no.... output is not what i wanted.

Let me clear you again...

If i set value of chkbox1 = true then
chkbox2=true
chkbox3=true
chkbox4=true
chkbox5=true
(set all other chkboxes=true) and
cmdStart.enabled=true

elseif i set value of chkbox1= false then
chkbox2=false
chkbox3=false
chkbox4=false
chkbox5=false
(set all other chkboxes=false) and
cmdStart.enabled=false

Also....
if i set value of chkbox2=false then check value of othe
chkboxes(3,4,5)
and if value of all chkboxes(3,4,5)=false then
cmdStart.enabled=false
elseif any of the chkboxes(3,4,5)=true then
cmdStart.enabled=true

same for other chkboxes(3,4,5) check and apply.

example is attached. plz see for reference

+-------------------------------------------------------------------
|Filename: Book6.zip
|Download: http://www.excelforum.com/attachment.php?postid=3453
+-------------------------------------------------------------------
 
I

ilyaskazi

Its ok. But your code has helped me solving it like this...


Code:
--------------------

Option Explicit

Private mEnableEvents As Boolean

Private Sub CheckBox1_Click()
With Me
If mEnableEvents Then
mEnableEvents = False
mEnableEvents = False
.CheckBox2.Value = .CheckBox1.Value
.CheckBox3.Value = .CheckBox1.Value
.CheckBox4.Value = .CheckBox1.Value
.CheckBox5.Value = .CheckBox1.Value
SetCheckboxes .CheckBox1
If .CheckBox1.Value Then
.cmdStart.Enabled = True
End If
mEnableEvents = True
mEnableEvents = True
End If
End With
End Sub

Private Sub CheckBox2_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox2
If .CheckBox2.Value Then
.cmdStart.Enabled = True
End If
End If
End With
End Sub

Private Sub CheckBox3_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox3
If .CheckBox3.Value Then
.cmdStart.Enabled = True
End If
End If
End With
End Sub

Private Sub CheckBox4_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox4
If .CheckBox4.Value Then
.cmdStart.Enabled = True
End If
End If
End With
End Sub

Private Sub CheckBox5_Click()
With Me
If mEnableEvents Then
SetCheckboxes .CheckBox5
If .CheckBox5.Value Then
.cmdStart.Enabled = True
End If
End If
End With
End Sub

Private Sub UserForm_Activate()
mEnableEvents = True
Me.cmdStart.Enabled = False
End Sub

Private Sub SetCheckboxes(thisCb As MSForms.CheckBox)
With Me
mEnableEvents = False
If Not thisCb.Value Then
.CheckBox1.Value = False
ElseIf .CheckBox2.Value And .CheckBox3.Value And _
.CheckBox4.Value And .CheckBox5.Value Then
.CheckBox1.Value = True
.cmdStart.Enabled = True
End If
If Not .CheckBox2.Value And Not .CheckBox3.Value And _
Not .CheckBox4.Value And Not .CheckBox5.Value Then
.cmdStart.Enabled = False
End If
mEnableEvents = True
End With
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