Count Property (Microsoft Access)

Applies To

Form, Report.

Description

You can use the Count property to determine the number of open forms or reports, or the number of controls on an open form or report.

Setting

The Count property setting is an Integer and is read-only in all views.

You can determine the Count property using a macro or Visual Basic.

If no forms or reports are open, the Count property setting is 0.

See Also

Count Property (Visual Basic), Count Property (Microsoft Office 95 Data Access Reference).

Example

The following example uses the Collection object’s Count property to specify how many iterations are required to remove all elements of the Collection object colThings. User-defined collections are indexed numerically. For a user-defined collection, the default base index is 1. Since collections are automatically reindexed when an item is removed, the following code removes the first member on each iteration.

Note that you can also use the For Each...Next statement to manipulate items in a collection.


Dim intIintI = 1 to colThings.Count
    colThings.Remove 1

The following example uses the Count property to control a loop that prints information about all open forms.


Sub Print_Form_Controls()
    Dim frm As Form, intI As Integer, intJ As Integer, strTab As String
    Dim intControls As Integer, intForms As Integer
    strTab = Chr(9)            ' Tab character.
    intForms = Forms.Count        ' Number of open forms.
    If intForms > 0 Then
        For intI = 0 To intForms - 1
            Set frm = Forms(intI)
            Debug.Print frm.Name        ' Print form name.
            intControls = frm.Count
            If intControls > 0 Then
                For intJ = 0 To intControls - 1
                    ' Print control name.
                    Debug.Print strTab; frm(intJ).Name    
                Next intJ
            Else
                Debug.Print strTab; "(no controls)"
            End If
        Next intI
    Else
        MsgBox "No open forms.", vbExclamation, "Form Controls"
    End IfSub

The next example determines the number of controls on a form or report and assigns this number to a variable.


Dim intFormControls As IntegerintReportControls As Integer= Forms![Employees].Count= Reports![FreightCharges].Count