PDA

View Full Version : Sleeper: Enable Option Button only if more than 2 checkboxes are checked



Djblois
09-14-2006, 04:34 AM
Is there a way I can have it enable a particular option button on a user form if the User checks more than one checkbox. And then if he unchecks it down to one he it will disable?

Djblois
09-14-2006, 04:50 AM
I see from another thread how I can set the option button to disable but how do I set an if more than one checkbox in a collection?

Bob Phillips
09-14-2006, 05:25 AM
Put this code in the procedure



Dim ctl As Control
Dim cCBs As Long
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Value Then
cCBs = cCBs + 1
End If
End If
Next ctl
OptionButton1.Enabled = cCBs > 1


and call the procedure from all checkbox click routines.

Djblois
09-14-2006, 05:40 AM
Where do I put the name of the option box? Where it says me should I put the name of the collection? Also would this disable the Option box again if the number of checks go down to 1?

Bob Phillips
09-14-2006, 05:42 AM
OptionButton1.

No, that refers to the userform container.

Yes.

Djblois
09-14-2006, 05:45 AM
Sub EnableOption()
Dim ctl As Control
Dim cCBs As Long
For Each ctl In DataView.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Value Then
cCBs = cCBs + 1
End If
End If
Next ctl
Column.Enabled = cCBs > 1
End Sub


It keeps telling me object required on the line:


For Each ctl In DataView.Controls

I tried the using the frame name (Dataview) and also the group name under properties for the checkboxes.

Bob Phillips
09-14-2006, 06:20 AM
What is DataView? You said you were suing a Userform, so use Me.

Djblois
09-14-2006, 10:02 AM
Whenever I use Me it says invalid use of me command

Bob Phillips
09-14-2006, 10:44 AM
So is it really a userform?

Djblois
09-14-2006, 02:14 PM
Maybe I am using the wrong terminology. I created a custom form in VBA.

Bob Phillips
09-14-2006, 02:31 PM
You did Insert>Userform in the VBIDE?

Djblois
09-14-2006, 02:39 PM
Yes

Bob Phillips
09-14-2006, 03:40 PM
Can you post the workbook?

Djblois
09-14-2006, 03:54 PM
ok