Count Property

Microsoft Access Visual Basic

You can use the Count property to determine the number of items in a specified collection. Read/write Integer.

expression.Count

expression    Required. An expression that returns one of the above objects.

ShowCount property as it applies to the all other object in the Applies To list.

You can use the Count property to determine the number of items in a specified collection. Read-only Long.

expression.Count

expression    Required. An expression that returns one of the above objects.

Setting

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

You can determine the Count property for an object by using a macro or Visual Basic.

Remarks

For example, if you want to determine the number of forms currently open or existing on the database, you would use the following code strings:

' Determine the number of open forms.

forms.count

' Determine the number of forms (open or closed)
' in the current database.

currentproject.allforms.count
		

Example

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

Sub Print_Form_Controls()
    Dim frm As Form, intI As Integer
    Dim intJ As Integer
    Dim intControls As Integer, intForms As Integer
    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
            intControls = frm.Count
            If intControls > 0 Then
                For intJ = 0 To intControls - 1
                    Debug.Print vbTab; frm(intJ).Name
                Next intJ
            Else
                Debug.Print vbTab; "(no controls)"
            End If
        Next intI
    Else
        MsgBox "No open forms.", vbExclamation, "Form Controls"
    End If
End Sub
		

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

Dim intFormControls As Integer
Dim intReportControls As Integer
intFormControls = Forms!Employees.Count
intReportControls = Reports!FreightCharges.Count