Well, yes you can, but I generally don't advise it. Here are two routines:
Function SetAccessProperty(obj As Object, strName As String, _
intType As Integer, varSetting As Variant) As Boolean
Dim prp As Property
Const conPropNotFound As Integer = 3270
On Error GoTo ErrorSetAccessProperty
' Explicitly refer to Properties collection.
obj.Properties(strName) = varSetting
obj.Properties.Refresh
SetAccessProperty = True
ExitSetAccessProperty:
Exit Function
ErrorSetAccessProperty:
If Err = conPropNotFound Then
' Create property, denote type, and set initial value.
Set prp = obj.CreateProperty(strName, intType, varSetting)
' Append Property object to Properties collection.
obj.Properties.Append prp
obj.Properties.Refresh
SetAccessProperty = True
Resume ExitSetAccessProperty
Else
MsgBox Err & ": " & vbCrLf & Err.Description
SetAccessProperty = False
Resume ExitSetAccessProperty
End If
End Function
Sub ModifyDefaultValue(tablename As String, _
fieldname As String, _
fieldvalue As Variant)
Dim dbs As Database, tdf As TableDef, fld As Field
Dim blnReturn As Boolean
' Return reference to current database.
Set dbs = CurrentDb
' Return reference to table and field.
Set tdf = dbs.TableDefs(tablename)
Set fld = tdf.Fields(fieldname)
' Call SetAccessProperty function.
blnReturn = SetAccessProperty(fld, _
"DefaultValue", dbLong, fieldvalue)
' Evaluate return value.
If blnReturn = True Then
Debug.Print "Property set successfully."
Else
Debug.Print "Property not set successfully."
End If
End Sub
'You could call the preceding function with a procedure such as the
following:
Sub test()
Call ModifyDefaultValue("FieldFormatTable", "Field1", 100)
End Sub
--
--Roger Carlson
MS Access MVP
Access Database Samples:
www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L