共用方式為


Access) (Forms.Count 屬性

使用 Count 屬性可判斷指定集合中的專案數。 唯讀的 Long

語法

運算式計數

表達 代表 Forms 物件的變數。

範例

例如,如果您想要判斷目前在資料庫中開啟或現有的表單數目,您會使用下列程式碼字串。

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

下列範例使用 Count 屬性來控制迴圈,列印所有開啟的表單及其控制項的相關資訊。

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

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應