ColumnOrder Property

Applies To

Bound Object Frame control, Chart control, Check Box control, Combo Box control, Field object, List Box control, Option Button control, Option Group control, QueryDef object, Table field, TableDef object, Text Box control, Toggle Button control.

Description

You can use the ColumnOrder property to specify the order of the columns in Datasheet view.

Note The ColumnOrder property applies to all fields in Datasheet view and to form controls when the form is in Datasheet view.

Setting

You can set this property by selecting a column in Datasheet view and dragging it to a new position.

You can also set this property by using a Long Integer value in Visual Basic.

To set or change this property for a table or query by using Visual Basic, you must use a field's Properties collection. For details, see Property Object, Properties Collection Summary.

Note The ColumnOrder property isn't available in Design view.

Remarks

In Datasheet view, a field's ColumnOrder property setting is determined by the field's position. 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. 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.

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). 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.

See Also

ColumnHidden property, ColumnWidth property, FrozenColumns property, RowHeight property.

Example

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
The next example displays the ProductName and QuantityPerUnit fields in the first two columns of the Products table in Datasheet view. 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 is closed and reopened.

Dim dbs As Database, tdfProducts As TableDef
Set dbs = CurrentDb
Set tdfProducts = dbs!Products
SetFieldProperty tdfProducts!ProductName, "ColumnOrder", dbLong, 2
SetFieldProperty tdfProducts!QuantityPerUnit, "ColumnOrder", dbLong, 3

Sub SetFieldProperty(fldField As Field, strPropertyName As String, _
        intPropertyType As Integer, varPropertyValue As Variant)
    ' Set field property without producing nonrecoverable run-time error.
    Const conErrPropertyNotFound = 3270
    Dim prpProperty As Property
    On Error Resume Next                ' Don't trap errors.
    fldField.Properties(strPropertyName) = varPropertyValue
    If Err <> 0 Then                    ' Error occurred when value set.
        If Err <> conErrPropertyNotFound Then
            On Error GoTo 0
            MsgBox "Couldn't set property '" & strPropertyName _
                & "' on field '" & fldField.name & "'", 48, "SetFieldProperty"
        Else
            On Error GoTo 0
            Set prpProperty = fldField.CreateProperty(strPropertyName, _
                intPropertyType, varPropertyValue)
            fldField.Properties.Append prpProperty
        End If
    End If
End Sub