Controls Collection

See Also9NH8E              Properties8DIV6J               Example138M7ZK>Low


A collection17X8LRK whose elements represent each controlXX9KJT on a form, including elements of control arrays8G7Y0UU.  The Controls collection has a single property3MRB2KQ, CountVN7VUP, that specifies the number of elements in an array.


[form.]Controls(index)[.property][ = setting ]

form (index)[.property][ = setting ]


The Controls collection enumerates loaded controls on a form and is useful for iterating through them.  The index in the syntax is between 0 and Controls.Count-1.  Note that Controls is a keyword but not a reserved word.  It identifies an intrinsic form-level variable named Controls.  If you omit the optional form reference, you must include the Controls keyword.  If you include a form reference, you can omit the Controls keyword.  For example, the following two lines have the same effect:

MyForm.Controls(6).Top = MyForm.Controls(5).Top + increment

MyForm(6).Top = MyForm(5).Top + increment

You can use Controls(index) as an argument to a function with a parameter of type Control.



See Also


Forms Collection1MV9U5Q


Programmer's Guide:

Chapter 3, "Creating and Using Controls"

Chapter 8, "Objects and Instances"

Controls Collection Example

The OBJECTS.MAK file referred to in Chapter 8 of the Programmer's Guide includes the following procedure to enable all currently loaded controls on a form (except menus).

Sub EnableControlsOn (Frm As Form, State As Integer)

   Dim I                                 ' Declare variable.

   For I = 0 To Frm.Controls.Count - 1

      If TypeOf Frm.Controls(I) Is Not Menu Then

         Frm.Controls(I).Enabled = State

      End If

   Next I

End Sub