Userform checkboxes question

chuckles1066

Banned
Joined
Dec 20, 2004
Messages
372
I have a userform with some checkboxes which relate to answers to questions.

Question 2 is related to question 1 insofar as if the user clicks NO to question 1, then question 2 becomes irrelevant.

No problem, I have a routine that sets both checkboxes associated with question 2 to enabled=false if NO is answered to question 1.

And if the user changes his/her mind and then clicks YES to question 1, both checkboxes associated with question 2 are set to enabled = true.

It all works well except.............if there is a tick in either of the question 2 checkboxes and those checkboxes are subsequently set to enabled=false, the ticks remain (albeit greyed out).

How can I clear the tick before setting enable to false?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Code:
Dim q1, q2, As Boolean

Private Sub CheckBox1_Change()
q1 = False
    Select Case CheckBox2.Value
        Case True
            CheckBox2.Value = False
        Case Else
            CheckBox1.Value = True
            CheckBox3.Enabled = True
            CheckBox4.Enabled = True
            Label2.ForeColor = &H80000012
    End Select
If CheckBox1.Value + CheckBox2.Value = -1 Then q1 = True
    Select Case CheckBox2.Value
        Case True
            q2 = True
            EnableOKButton
        Case Else
            q2 = False
            EnableOKButton
    End Select
End Sub

Private Sub CheckBox2_Change()
q1 = False
    Select Case CheckBox1.Value
        Case True
            CheckBox1.Value = False
        Case Else
            CheckBox2.Value = True
            CheckBox3.Enabled = False
            CheckBox4.Enabled = False
            Label2.ForeColor = &H80000011
    End Select
If CheckBox1.Value + CheckBox2.Value = -1 Then q1 = True
    Select Case CheckBox2.Value
        Case True
            q2 = True
            EnableOKButton
        Case Else
            EnableOKButton
    End Select
End Sub

Private Sub CheckBox3_Change()
q2 = False
    Select Case CheckBox4.Value
        Case True
            CheckBox4.Value = False
        Case Else
            CheckBox3.Value = True
    End Select
If CheckBox3.Value + CheckBox4.Value = -1 Then q2 = True
EnableOKButton
End Sub

Private Sub CheckBox4_Change()
q2 = False
    Select Case CheckBox3.Value
        Case True
            CheckBox3.Value = False
        Case Else
            CheckBox4.Value = True
    End Select
If CheckBox3.Value + CheckBox4.Value = -1 Then q2 = True
EnableOKButton
End Sub

Private Sub CommandButton1_Click()
cb1v = CheckBox1.Value
cb2v = CheckBox2.Value
cb3v = CheckBox3.Value
cb4v = CheckBox4.Value
Unload Me
End Sub

Private Sub UserForm_Initialize()
quit = False
CheckBox1.Value = False
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
CommandButton1.Enabled = False
End Sub

Sub EnableOKButton()
If q1 And q2 Then
    CommandButton1.Enabled = True
        Else
    CommandButton1.Enabled = False
End If
End Sub
 
Upvote 0
By the way, post #3 is my code, not an attempt at a solution!

(Apologies for the new post, couldn't see how to edit a post!)
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top