ColumnOrder Property

Applies To

Table Fields.

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 set this property by selecting a column in Datasheet view and dragging it to a new position.

You set the ColumnOrder property in Visual Basic using a Long value.

To set or change this property for a table or query using Visual Basic, you must use a field’s Properties collection.

Note The ColumnOrder property is not available in form 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 ColumnOrder property for that field and every field to the left of its original position in Datasheet view.

In other views, the ColumnOrder 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 ColumnOrder 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![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.


Dim db As Database, tdProducts As TableDefdb = CurrentDbtdProducts = db![Products]tdProducts![ProductName], "ColumnOrder", dbLong, 2tdProducts![QuantityPerUnit], "ColumnOrder", dbLong, 3
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 proProperty 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 proProperty = fldField.CreateProperty(strPropertyName, _
                intPropertyType, varPropertyValue)
            fldField.Properties.Append proProperty
        End If
    End IfSub