The behaviour that you are describing for your controls sounds similar to that of having multiple checkboxes accompanied by a Select All checkbox to simultaneously enable or disable all checkboxes in the set:
To achieve this, I believe you will need to use some VBA code in the various After Update
event handlers for your controls.
In the following example, I am assuming that you have a set of checkboxes called chk1
, chk2
, and chk3
and a single Select All checkbox called chkA
(however, this could be expanded to any number of checkboxes by simply increasing the upper limit of the For
loops).
You could then achieve the desired behaviour using the following two functions:
A function to toggle all option checkboxes to a given value:
Function ToggleAll(v As Integer)
Dim i As Integer
For i = 1 To 3
Controls("chk" & i).Value = v
Next i
End Function
A function to test whether or not all option checkboxes are enabled and enable or disable the Select All checkbox accordingly:
Function AllEnabled()
Dim i As Integer, v As Integer: v = -1
For i = 1 To 3
v = v * Abs(Controls("chk" & i).Value)
Next i
chkA.Value = v
End Function
Then, you simply need to evaluate the above functions from within the After Update
event handlers for your controls:
Private Sub chk1_AfterUpdate()
AllEnabled
End Sub
Private Sub chk2_AfterUpdate()
AllEnabled
End Sub
Private Sub chk3_AfterUpdate()
AllEnabled
End Sub
Private Sub chkA_AfterUpdate()
ToggleAll chkA
End Sub
Here, every time the value of the individual option checkboxes is altered, the AllEnabled
function checks whether all option checkboxes are enabled and sets the value of the Select All checkbox accordingly.
When the value of the Select All checkbox (chkA
) is modified, the ToggleAll
function is evaluated, simultaneously enabling or disabling the setting of all option checkboxes on the form.