Group checks

  • Thread starter Thread starter Terry
  • Start date Start date
T

Terry

Hello
Is there a way to group checkboxes so that if any of the boxes are checked
or changed, it sets a property for another control?

EX: If any of the 65 checkboxes I have on my form are checked, it sets a
visible propery to a textbox to true. The checkboxes all have thier name
beginning with "chk".
I want to try to avoid putting an "on_click" on each checkbox, because they
would all do the same thing.

Thank you so much
Terry V
 
Terry,

There's no automatic way to do it, but you could use this method:

1. Give the textboxes the same root name as the checkboxes, for example
chkText1 and txtText1.

2. Create a public function in your form, like so:
Public Function EnableTextBox() As Boolean
Dim sName As String

sName = "txt" & Mid(Screen.ActiveControl.Name, 3)
DisableControls 'See below
Me(sName).Enabled = True
End Function

3. Add the following to the OnClick property for each checkbox:
=EnableTextBox()

If you need to disable previously enabled textboxes, for example, if the
checkboxes are mutually exclusive, you'll need to build a procedure to
disable them all before you enable the one you want. Before you do that, you
need to identify which one's belong to the "group" in question. To that end,
you could assign a value (a group name) to their Tag property.
Private Sub DisableTextBoxes()
Dim ctrl As Control

For Each ctrl In Me.Controls
If ctrl.ControlType = acTextBox Then
If ctrl.Tag = "somevalue" Then
ctr.Enabled = False
End If
End If
Next ctrl
End Sub

However, if the checkboxes are mutually exclusive, you should be using
option boxes contained within an option group. In that way, the frame
(option group) will handle the mutual exlusion functionality, plus give you
a single value. If that's the case, let us know, 'cause you'd use a
different method.

Graham R Seach
Microsoft Access MCP, MVP
Sydney, Australia
 
Back
Top