ComboBox.ListCount 屬性 (Access)ComboBox.ListCount property (Access)

您可以使用 ListCount 屬性來判斷在下拉式方塊的清單方塊部分中的列數。You can use the ListCount property to determine the number of rows in the list box portion of a combo box. 讀取/寫入 Read/write Long.

語法Syntax

運算式ListCountexpression.ListCount

_運算式_代表**ComboBox** 物件的變數。expression A variable that represents a ComboBox object.

註解Remarks

Microsoft Access 將 ListCount 屬性設定為列數在清單方塊或下拉式方塊的清單方塊部分。Microsoft Access sets the ListCount property to the number of rows in the list box or the list box portion of the combo box. ListCount 屬性的值是唯讀屬性並不會在使用者設定。The value of the ListCount property is read-only and can't be set by the user.

此屬性是只能透過使用巨集或 Visual Basic 中。This property is available only by using a macro or Visual Basic. 您可以讀取此屬性只能在表單檢視] 和 [資料工作表檢視。You can read this property only in Form view and Datasheet view.

決定控制項的 資料來源 ] 和 [ RowSourceType 屬性並由 ListCount 屬性設定會包含下拉式方塊清單或清單方塊中的資料列的總數。The ListCount property setting contains the total number of rows in the combo box list or list box, as determined by the control's RowSource and RowSourceType properties. 控制項根據資料表或查詢 ( RowSourceType 屬性設定為 [資料表/查詢與 RowSource 屬性設定為特定的資料表或查詢) ListCount 屬性設定值包含資料表或查詢結果集中的記錄數目。If the control is based on a table or query (the RowSourceType property is set to Table/Query and the RowSource property is set to a particular table or query), the ListCount property setting contains the number of records in the table or query result set. 如果RowSourceType屬性設為 Value List, ListCount屬性設定值包含 [值] 清單中的RowSource屬性結果中指定的列數 (這取決於 [值] 清單及欄數清單方塊或下拉式方塊清單中,檢閱 ColumnCount屬性設為)。If the RowSourceType property is set to Value List, the ListCount property setting contains the number of rows that the value list specified in the RowSource property results in (this depends on the value list and the number of columns in the list box or combo box list, as set by the ColumnCount property).

如果您將 ColumnHeads 屬性設定為 [是] 時的欄標題列隨附於 ListCount 屬性所傳回的列數。If you set the ColumnHeads property to Yes, the row of column headings is included in the number of rows returned by the ListCount property. 下拉式方塊和清單方塊的基礎資料表或查詢,新增的欄標題新增額外的資料列。For combo boxes and list boxes based on a table or query, adding column headings adds an additional row. 下拉式方塊和清單方塊的值] 清單為基礎,新增的欄標題會保留不變的列數 (第一列的值會變成欄標題)。For combo boxes and list boxes based on a value list, adding column headings leaves the number of rows unchanged (the first row of values becomes the column headings).

您可用於 ListCount 屬性與 ListRows 屬性指定您想要顯示在下拉式方塊的清單方塊部分中的資料列數目。You can use the ListCount property with the ListRows property to specify how many rows you want to display in the list box portion of a combo box.

範例Example

下列範例會使用ListCount屬性來尋找Customers ] 表單上的 [清單] 下拉式方塊清單方塊部分中的列數。The following example uses the ListCount property to find the number of rows in the list box portion of the CustomerList combo box on a Customers form. 然後將設定 ListRows 屬性來顯示在清單中指定的資料列數目。It then sets the ListRows property to display a specified number of rows in the list.

Public Sub SizeCustomerList() 
 
 Dim ListControl As Control 
 
 Set ListControl = Forms!Customers!CustomerList 
 With ListControl 
 If .ListCount < 8 Then 
 .ListRows = .ListCount 
 Else 
 .ListRows = 8 
 End If 
 End With 
 
End Sub

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.