Object Collections

  • Thread starter Thread starter Martin Dashper
  • Start date Start date
M

Martin Dashper

I want to create a collection, if possible, to contain a group of
checkboxes in order to perform operations on them all at once.
Is this possible, and, if so, how?

Martin Dashper
 
Yes it is, but it's not clear if these exist on a form or purely within
code.

What you may want to consider if this is a form is to set the .Tag property
to identify the collection. You can then enumerate the controls on the form
looking for the tag and then perform the opperation.
 
Yes it is, but it's not clear if these exist on a form or purely within
code.

What you may want to consider if this is a form is to set the .Tag property
to identify the collection. You can then enumerate the controls on the form
looking for the tag and then perform the opperation.
I have several groups of checkboxes on a form and what I want to do is
control each group separately, for example, disable all the checkboxes
in a group at once.

Martin Dashper
 
Martin,

Write a public function in your form module that performs the operations you
want for the checkboxes. Then select all the checkboxes, go to properties -
event tab amd enter the following:
=NameOfYourFunction
 
Martin Dashper said:
I have several groups of checkboxes on a form and what I want to do is
control each group separately, for example, disable all the checkboxes
in a group at once.

As JohnFol suggested, I use the Tag property for that. For example, I
might have some controls with their tags set to A, and some with their
tags set to B. Then I'd have code like this:

'----- start of code -----
Public Sub EnableControlGroup( _
frm As Access.Form, _
GroupID As String, _
YesOrNo As Boolean)

Dim ctl As Access.Control

For Each ctl in frm.Controls

If ctl.Tag = GroupID Then
ctl.Enabled = YesOrNo
End If

Next ctl

End Sub
'----- end of code -----

That would allow me to write, in code behind a form,

' Enable controls in group B.
EnableFormControls Me, "B", True
Me.SomeControlInB.SetFocus

' Disable controls in group A.
EnableFormControls Me, "A", False

A more elaborate version of the function would allow you to pass the
property you want to set for the group, and its value.
 
Back
Top