Controls Collection

Description

The Controls collection contains all of the controls on a form or report. The Controls collection is a member of a Form or Report object.

Remarks

You can enumerate individual controls, count them, and set their properties in the Controls collection. For example, you can enumerate the Controls collection of a particular form and set the Height property of each control to a specified value.

Tip The For Each...Next statement is useful for enumerating a collection.

It is faster to refer to the Controls collection implicitly, as in the following examples, which refer to a control called NewData on a form named OrderForm. Of the following syntax examples, Me!NewData is the fastest way to refer to the control.


Me!NewData    ' Or Forms!OrderForm!NewData.![New Data]    ' Use if control name contains space.("NewData")    ' Performance slightly slower.

You can also refer to an individual control by referring explicitly to the Controls collection.


Me.Controls!NewData    ' Or Forms!OrderForm.Controls!NewData..Controls![New Data].Controls("NewData")

Additionally, you can refer to a control by its index in the collection. The Controls collection is indexed beginning with zero.


Me(0)    ' Refer to first item in collection..Controls(0)

Note You can use the Me keyword to represent a form or report within code only if you’re referring to the form or report from code within the form module or report module. If you’re referring to a form or report from a standard module or a different form or report’s module, you must use the full reference to the form or report.

Properties

Count Property (Microsoft Access).

See Also

Control Object, For Each...Next Statement, Form Object, Me, Report Object.

Example

See the Control object example.