Count 屬性

此頁沒有內(nèi)容條目
內(nèi)容

expandtri全部顯示

blueup應(yīng)用于窗體和報表對象的 Count 屬性

使用 Count 屬性可以判斷指定集合中的項目個數(shù)。Integer 型,可讀/寫。

expression.Count

expression     必需。返回以上對象之一的表達式。

blueup應(yīng)用于“應(yīng)用目標(biāo)”列表中所有其他對象的 Count 屬性。

使用 Count 屬性可以判斷指定集合中的項目個數(shù)。Long 型,只讀。

expression.Count

expression     必需。返回以上對象之一的表達式。

設(shè)置

Count 屬性設(shè)置是整型值,且在所有視圖中都是只讀的。

可以使用Visual Basic 確定對象的 Count 屬性。

說明

例如,如果要確定當(dāng)前打開的窗體個數(shù)或數(shù)據(jù)庫中現(xiàn)有的窗體個數(shù),則可以使用以下代碼:

' Determine the number of open forms.

forms.count

' Determine the number of forms (open or closed)

' in the current database.

currentproject.allforms.count

示例

以下示例使用 Count 屬性控制循環(huán),該循環(huán)用于打印所有打開的窗體及其控件的信息。

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

下一示例判斷窗體或報表中控件的數(shù)目,然后將該數(shù)目賦給一個變量。

Dim intFormControls As Integer

Dim intReportControls As Integer

intFormControls = Forms!Employees.Count

intReportControls = Reports!FreightCharges.Count