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

當您由下拉式方塊選取時,BoundColumn 屬性會告訴 Microsoft Access 用哪個資料行的值來當做控制項的值。When you make a selection from a combo box, the BoundColumn property tells Microsoft Access which column's values to use as the value of the control. 如果控制項有繫結至欄位, BoundColumn屬性所指定欄的值儲存在名為ControlSource屬性中的欄位。If the control is bound to a field, the value in the column specified by the BoundColumn property is stored in the field named in the ControlSource property. 可讀寫的 LongRead/write Long.

語法Syntax

運算式BoundColumnexpression.BoundColumn

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

註解Remarks

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

設定Setting 描述Description
00 ListIndex屬性值,而不是資料行的值,會儲存在目前的記錄。The ListIndex property value, rather than the column value, is stored in the current record. 第一資料列的 ListIndex 屬性值是 0,第二資料列是 1,依此類推。The ListIndex property value of the first row is 0, the second row is 1, and so on. 當清單方塊或下拉式方塊的清單方塊部分中選取項目時,access 就會設定ListIndex屬性。Access sets the ListIndex property when an item is selected from a list box or the list box portion of a combo box. 例如,如果您只想儲存數目的順序時,請設定 BoundColumn 屬性為 0,並使用可能會用到的 ListIndex 控制項屬性值。Setting the BoundColumn property to 0 and using the ListIndex property value of the control might be useful if, for example, you are only interested in storing a sequence of numbers.
1 或更大1 or greater (預設值為 1)指定資料行中的值會成為控制項的值。(Default is 1) The value in the specified column becomes the control's value. 如果控制項有繫結至欄位,此設定會儲存於該欄位中的目前記錄。If the control is bound to a field, this setting is stored in that field in the current record. BoundColumn屬性無法設定為值大於ColumnCount屬性的設定。The BoundColumn property can't be set to a value larger than the setting of the ColumnCount property.

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

在 Visual Basic 之中,請使用數字或數值運算式 (由 0 到 ColumnCount 屬性的設定值) 來設定 BoundColumn 屬性。In Visual Basic, set the BoundColumn property by using a number or a numeric expression equal to a value from 0 to the setting of the ColumnCount property.

下拉式方塊中最左邊顯示的資料行 (下拉式方塊的ColumnWidths屬性設定值不是最左邊的欄 0) 包含出現在下拉式方塊在表單檢視或報表中的文字] 方塊部分中的資料。The leftmost visible column in a combo box (the leftmost column whose setting in the combo box's ColumnWidths property is not 0) contains the data that appears in the text box part of the combo box in Form view or in a report. 當您選取範圍時,BoundColumn 屬性決定要儲存文字方塊或下拉式方塊兩者之一的資料行值。The BoundColumn property determines which column's value in the text box or combo box list will be stored when you make a selection. 此舉允許您顯示不同於原來儲存當做控制項的資料。This allows you to display different data than you store as the value of the control.

注意

如果繫結資料行不是控制項中最左邊顯示的資料行相同 (或如果您設定BoundColumn屬性設為 0), LimitToList屬性設定為 [是]。If the bound column is not the same as the leftmost visible column in the control (or if you set the BoundColumn property to 0), the LimitToList property is set to Yes.

Access 會使用以零為基礎的數字參照Column屬性中的資料行。Access uses zero-based numbers to refer to columns in the Column property. 也就是第一欄由使用運算式中參照Column(0),第二欄由使用運算式參照Column(1),依此類推。That is, the first column is referenced by using the expression Column(0), the second column is referenced by using the expression Column(1), and so on. 不過,BoundColumn 屬性則使用以 1 為開始的數值去參照資料行。However, the BoundColumn property uses 1-based numbers to refer to the columns. 這表示如果BoundColumn屬性設為 1,您可以存取儲存在該欄中使用運算式的值Column(0)This means that if the BoundColumn property is set to 1, you could access the value stored in that column by using the expression Column(0).

如果AutoExpand屬性設定為 [是],Access 會自動填入符合下拉式方塊清單中的值,當您輸入的下拉式方塊的文字方塊部分中的值。If the AutoExpand property is set to Yes, Access automatically fills in a value in the text box portion of the combo box that matches a value in the combo box list as you type.

範例Example

下列範例會示範如何建立時顯示另一個繫結至一欄的下拉式方塊。The following example shows how to create a combo box that is bound to one column while displaying another. 設定 ColumnCount 的屬性為 2,即表示 cboDept 下拉式方塊會顯示由 RowSource 屬性所指定資料來源的前兩欄。Setting the ColumnCount property to 2 specifies that the cboDept combo box will display the first two columns of the data source specified by the RowSource property. 設定 BoundColumn 的屬性為 1 ,即表示當您檢查下拉式方塊的值時,會將儲存於第一欄的值傳回。Setting the BoundColumn property to 1 specifies that the value stored in the first column will be returned when you inspect the value of the combo box.

ColumnWidths屬性會指定兩個資料行的寬度。The ColumnWidths property specifies the width of the two columns. 藉由將第一欄寬度設定為 0 英吋,第一欄便不會顯示在下拉式方塊。By setting the width of the first column to 0in., the first column is not displayed in the combo box.

Private Sub cboDept_Enter()
    With cboDept
        .RowSource = "SELECT * FROM tblDepartments ORDER BY Department"
        .ColumnCount = 2
        .BoundColumn = 1
        .ColumnWidths = "0in.;1in."
    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.