PDA

View Full Version : Setting checkboxes with Boolean effect



JSA715
08-04-2008, 03:45 PM
I have a list of control checkboxes on a form within a frame, Alpha - Delta, and a checkbox by itself, Zulu. I need an efficient script that will do the following.

Private Sub Alpha_Click()

If Zulu.Value = True Then

if alpha.value = true then
bravo.value = false
bravo.enabled = false
charlie.value = false
charlie.enabled = false
delta.value = false
delta.enabled = false

Elseif alpha.value = false then
bravo.enabled = true
charlie.enabled = true
delta.enabled = true

end if

end if


They will work like normal check boxes until Zulu is set to True.

Once Zulu is set to true, all boxes are set to false, then if one box is set to true, the rest are disabled. If that same box is set back to false, the rest are enabled and set to false.

Im extremely new to VBA and am just having to pick it up as needed. In reality, I have about 20 of these boxes needing different combinations of this formula. Can anyone point me in the right direction?

Bob Phillips
08-04-2008, 04:45 PM
Use OptionButtons, that is their default bahviour.

JSA715
08-04-2008, 07:29 PM
Thats true in part, but when zulu isnt checked, all boxes can be check.

Bob Phillips
08-05-2008, 01:24 AM
I think there are two situations that need clarificication.

Say Zulu is checked, then Bravo gets checked, al others are disabled. What should happen if ZUlu is unchecked?

If Zulu is unchecked, and say Alpha, Bravo, Charlie are checked, then Zulu gets checked, what happens to the others?

JSA715
08-05-2008, 04:09 AM
Q1 - If Zulu is unchecked, the other boxes in a frame, Alpha - Delta, are all enabled and set to false.

Q2- If Zulu is unchecked and others are checked, then Zulu is checked, alpha-delta are set to false. Then once one is checked, the rest are disabled.

JSA715
08-08-2008, 09:17 AM
So Im guessing that there is no available solution to my problem?

Bob Phillips
08-08-2008, 09:43 AM
This seems to do it



Private ReEntryFlag As Boolean

Private Sub Alpha_Click()
If Not ReEntryFlag Then
ReEntryFlag = True
SetBoxes Me.Alpha
ReEntryFlag = False
End If
End Sub
Private Sub Bravo_Click()
If Not ReEntryFlag Then
ReEntryFlag = True
SetBoxes Me.Bravo
ReEntryFlag = False
End If
End Sub
Private Sub Charlie_Click()
If Not ReEntryFlag Then
ReEntryFlag = True
SetBoxes Me.Charlie
ReEntryFlag = False
End If
End Sub
Private Sub Delta_Click()
If Not ReEntryFlag Then
ReEntryFlag = True
SetBoxes Me.Delta
ReEntryFlag = False
End If
End Sub
Private Sub Zulu_Click()
Alpha.Enabled = True
Alpha.Value = False
Bravo.Enabled = True
Bravo.Value = False
Charlie.Enabled = True
Charlie.Value = False
Delta.Enabled = True
Delta.Value = False
End Sub

Private Function SetBoxes(this As MSForms.Control)
Dim ctl As MSForms.Control

If Me.Zulu.Value Then

For Each ctl In Me.Controls

If TypeName(ctl) = "CheckBox" Then

If Not ctl Is this And ctl.Name <> "Zulu" Then

If this.Value Then

ctl.Enabled = False
Else

ctl.Enabled = True
ctl.Value = False
End If
End If
End If
Next ctl
End If
End Function

JSA715
08-22-2008, 10:19 AM
THATS IT! Perfect! Thank so much!