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

您可以使用 LimitToList 屬性來限制下拉式方塊的值為清單項目。You can use the LimitToList property to limit a combo box's values to the listed items. 可讀寫的 BooleanRead/write Boolean.

語法Syntax

運算式LimitToListexpression.LimitToList

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

註解Remarks

LimitToList 屬性使用下列設定值。The LimitToList property uses the following settings.

設定Setting Visual BasicVisual Basic 描述Description
Yes TrueTrue Microsoft Access 會接受使用者在下拉式方塊內選取的清單項目,或輸入符合清單項目的文字。If the user selects an item from the list in the combo box or enters text that matches a listed item, Microsoft Access accepts it. 如果輸入的文字不符合所列的項目,不會接受文字,使用者必須再重新輸入項目、 選取清單項目、 按下 esc 鍵,或選擇 [編輯] 功能表上的 [復原]If the entered text doesn't match a listed item, the text isn't accepted and the user must then retype the entry, select a listed item, press Esc, or choose Undo on the Edit menu.
No FalseFalse (預設值)Access 接受符合**ValidationRule** 屬性的任何文字。(Default) Access accepts any text that conforms to the ValidationRule property.

對於資料表欄位,您可以在資料表設計檢視的 [欄位屬性] 區段的 [查閱] 索引標籤上設定此屬性,將DisplayControl屬性設定為下拉式方塊。For table fields, you can set this property on the Lookup tab of the Field Properties section of table Design view for fields with the DisplayControl property set to Combo Box.

注意

Access 會自動設定LimitToList屬性,當您選取 [查閱精靈] 當做資料表 [設計檢視中的欄位資料類型。Access sets the LimitToList property automatically when you select Lookup Wizard as the data type for a field in table Design view.

當結合下拉式方塊 (繫結控制項) 的 LimitToList 屬性設定為 [否] 時,您可以在下拉式方塊輸入不包含在清單中的值。When the LimitToList property of a bound combo box is set to No, you can enter a value in the combo box that isn't included in the list. 存取表單的基礎資料表或查詢 (在下拉式方塊的**ControlSource** 屬性中指定的欄位),不資料表或查詢中設定下拉式方塊的**RowSource** 屬性所儲存的新值。Access stores the new value in the form's underlying table or query (in the field specified in the combo box's ControlSource property), not the table or query set for the combo box by the RowSource property. 若要新輸入值會出現在下拉式方塊中,您必須新增新的值至資料表或查詢使用巨集或 Visual Basic 事件程序執行NotInList事件發生時,來設定RowSource屬性中。To have newly entered values appear in the combo box, you must add the new value to the table or query set in the RowSource property by using a macro or Visual Basic event procedure that runs when the NotInList event occurs.

設定LimitToList屬性和**AutoExpand** 屬性是可讓 Access 找到相符的值,從清單中,當使用者在下拉式方塊的文字方塊部分中輸入字元而且限制輸入項僅為那些值。Setting both the LimitToList property and the AutoExpand property to Yes lets Access find matching values from the list as the user enters characters in the text box portion of the combo box, and restricts the entries to only those values.

注意

如果您將下拉式方塊的**BoundColumn** 屬性到第一個顯示的資料行以外的任何資料行 (或如果您設定BoundColumn為 0), LimitToList屬性會自動設為 [是]。If you set the combo box's BoundColumn property to any column other than the first visible column (or if you set BoundColumn to 0), the LimitToList property is automatically set to Yes.

LimitToList屬性設定為 [是],並會在使用者選取下拉式方塊旁的箭號時,Access 會選取相符的值清單中為使用者在下拉式方塊的文字方塊部分輸入字元即使AutoExpand屬性設定為[否]。When the LimitToList property is set to Yes and the user selects the arrow next to the combo box, Access selects matching values in the list as the user enters characters in the text box portion of the combo box, even if the AutoExpand property is set to No. 如果使用者按下 enter 鍵或移動到另一個控制項或記錄,將選取的值會出現在下拉式方塊。If the user presses Enter or moves to another control or record, the selected value appears in the combo box.

LimitToList 屬性設定為 [是] 或 True 時,不管清單中是否包含 null 值,下拉式方塊都會接受 null 值。Combo boxes accept null values when the LimitToList property is set to Yes or True, whether or not the list contains null values. 如果您想要防止使用者在下拉式方塊中輸入null值,請在要在下拉式方塊結合為 [是] 資料表中設定欄位的必要屬性。If you want to prevent users from entering a null value in a combo box, set the Required property of the field in the table to which the combo box is bound to Yes.

範例Example

下列範例限制指定下拉式方塊的值為其清單項目。The following example limits a given combo box's values to its listed items.

Forms("Order Entry").Controls("States").LimitToList = True  

支援和意見反應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.