The Forms collection contains all of the currently open forms in a Microsoft Access database.
Use the Forms collection in Visual Basic or in an expression to refer to forms that are currently open. For example, you can enumerate the Forms collection to set or return the values of properties of individual forms in the collection.
Tip The For Each...Next statement is useful for enumerating a collection.
You can’t add or delete a Form object from the Forms collection.
You can refer to an individual Form object in the Forms collection either by referring to the form by name, or by referring to its index within the collection.
The Forms collection is indexed beginning with zero. If you refer to a form by its index, the first form is Forms(0), the second form is Forms(1), and so on.
Note To list all forms in the database, whether open or closed, enumerate the Documents collection of the Forms Container object. You can then use the Name property of each individual Document object to return the name of a form.
Count Property.
Application Object; For Each...Next Statement; Form Object; Microsoft Office 95 Data Access Reference: Container Object, Document Object, Documents Collection.
The following example enumerates the Forms collection and prints the name of each form in the Forms collection. It then enumerates the Controls collection of each form and prints the name of each control on the form.
Sub AllOpenForms() Dim frm As Form, ctl As Control ' Enumerate Forms collection. For Each frm In Forms ' Print name of form. Debug.Print frm.Name ' Enumerate Controls collection of each form. For Each ctl In frm.Controls ' Print name of each control. Debug.Print ">>>"; ctl.Name Next ctl Next frmSub
The following example uses the Forms collection in an expression. If you have a form OrderForm with a control ShipCountry, you can use the IIf function to return a value based on the current value of the control. If the value of ShipCountry is Null, the expression returns a zero-length string; otherwise, it returns the field’s contents. Enter the following expression in the ControlSource property of a text box on a form.
= IIf(IsNull(Forms![Orders]![ShipCountry]), "", _ Forms![Orders]![ShipCountry])