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

ColumnOrder 屬性可用於資料工作表檢視中指定欄的順序。You can use the ColumnOrder property to specify the order of the columns in Datasheet view. 可讀寫的 IntegerRead/write Integer.



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


[!注意事項] 若要設定或變更此屬性對於資料表或查詢使用 Visual Basic,您必須使用資料行的 Properties 集合。To set or change this property for a table or query by using Visual Basic, you must use a column's Properties collection. 如需使用Properties集合的詳細資訊,請參閱**屬性**。For more information about using the Properties collection, see Properties.

[!注意事項] 無法使用 ColumnOrder 屬性在設計檢視中。The ColumnOrder property isn't available in Design view.

當表單處於資料工作表檢視 ColumnOrder 屬性可套用於 [資料工作表檢視中的全部欄位和表單控制項。The ColumnOrder property applies to all fields in Datasheet view and to form controls when the form is in Datasheet view.

在資料工作表檢視] 中的欄位 ColumnOrder 屬性設定值取決於該欄位的位置。In Datasheet view, a field's ColumnOrder property setting is determined by the field's position. 例如,最左邊的欄資料工作表檢視中的欄位具有 ColumnOrder 屬性設定為 1 下, 一個功能變數,其設定為 2,依此類推。For example, the field in the leftmost column in Datasheet view has a ColumnOrder property setting of 1, the next field has a setting of 2, and so on. 變更欄位的 ColumnOrder 屬性會針對該欄位和每個欄位的屬性重設左邊的 [資料工作表檢視其原始位置。Changing a field's ColumnOrder property resets the property for that field and every field to the left of its original position in Datasheet view.

在其他檢視中的屬性設定為 0 除非您明確地變更 (不論是藉由將欄位拖曳至新位置或變更其 ColumnOrder 屬性設定值) 的資料工作表檢視] 中的一或多個欄位的順序。In other views, the property setting is 0 unless you explicitly change the order of one or more fields in Datasheet view (either by dragging the fields to new positions or by changing their ColumnOrder property settings). 移動的欄位的新位置的右側的欄位以外的資料工作表檢視的檢視中有屬性設定為 0。Fields to the right of the moved field's new position will have a property setting of 0 in views other than Datasheet view.

在 [資料工作表檢視] 中的欄位順序,不會影響在資料表設計檢視或表單檢視中的欄位順序。The order of the fields in Datasheet view doesn't affect the order of the fields in table Design view or Form view.


下列範例會顯示 [ ProductNameQuantityPerUnit欄位中資料工作表檢視中之Products表單中的前兩個資料行。The following example displays the ProductName and QuantityPerUnit fields in the first two columns in Datasheet view of the Products form.

Forms!Products!ProductName.ColumnOrder = 1 
Forms!Products!QuantityPerUnit.ColumnOrder = 2

下列範例會顯示 [ ProductNameQuantityPerUnit欄位中資料工作表檢視中將Products資料表的前兩個資料行。The following example displays the ProductName and QuantityPerUnit fields in the first two columns of the Products table in Datasheet view. 若要設定ColumnOrder屬性,此範例會使用SetFieldProperty程序。To set the ColumnOrder property, the example uses the SetFieldProperty procedure. 如果當資料表開啟時此程序正在執行,則所做的變更在資料表被關閉和重新開啟後才會顯示。If this procedure is run while the table is open, changes will not be displayed until it is closed and reopened.

Public Sub SetColumnOrder() 
 Dim dbs As DAO.Database 
 Dim tdf As DAO.TableDef 
 Set dbs = CurrentDb 
 Set tdf = dbs!Products 
 ' Call the procedure to set the ColumnOrder property. 
 SetFieldProperty tdf!ProductName, "ColumnOrder", dbLong, 2 
 SetFieldProperty tdf!QuantityPerUnit, "ColumnOrder", dbLong, 3 
 Set tdf = Nothing 
 Set dbs = Nothing 
End Sub 
Private Sub SetFieldProperty(ByRef fld As DAO.Field, _ 
 ByVal strPropertyName As String, _ 
 ByVal intPropertyType As Integer, _ 
 ByVal varPropertyValue As Variant) 
 ' Set field property without producing nonrecoverable run-time error. 
 Const conErrPropertyNotFound = 3270 
 Dim prp As Property 
 ' Turn off error handling. 
 On Error Resume Next 
 fld.Properties(strPropertyName) = varPropertyValue 
 ' Check for errors in setting the property. 
 If Err <> 0 Then 
 If Err <> conErrPropertyNotFound Then 
 On Error GoTo 0 
 MsgBox "Couldn't set property '" & strPropertyName & _ 
 "' on field '" & fld.Name & "'", vbCritical 
 On Error GoTo 0 
 Set prp = fld.CreateProperty(strPropertyName, intPropertyType, _ 
 fld.Properties.Append prp 
 End If 
 End If 
 Set prp = Nothing 
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.