1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Public Function SetColumnOrder()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("tObjets")
' Call the procedure to set the ColumnOrder property.
SetFieldProperty tdf.Fields("Objets_Id"), "ColumnOrder", dbLong, 1
SetFieldProperty tdf.Fields("Objets_NomCourt"), "ColumnOrder", dbLong, 2
SetFieldProperty tdf.Fields("Objets_Complements"), "ColumnOrder", dbLong, 3
Set tdf = Nothing
Set dbs = Nothing
End Function
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
Else
On Error GoTo 0
Set prp = fld.CreateProperty(strPropertyName, intPropertyType, _
varPropertyValue)
fld.Properties.Append prp
End If
End If
Set prp = Nothing
End Sub |
Partager