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/...UBED1=ACCESS-L
"Jim Thacker" <(E-Mail Removed)> wrote in message
news:C9FC87C3-9E1E-433C-8E75-(E-Mail Removed)...
> Sorry Roger, I didn't make my question clear.
> I want to change the DefaultValue of a table field when I change the value
> of a textbox (using the AfterUpdate Event) in an unrelated form.
> --
> Thanks, Jim
>
>
> "Roger Carlson" wrote:
>
>> Put the value you want in the Default property of the table in Design
>> View.
>>
>> --
>> --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/...UBED1=ACCESS-L
>>
>>
>> "Jim Thacker" <(E-Mail Removed)> wrote in message
>> news:EA9A8CC3-9776-499A-9F9F-(E-Mail Removed)...
>> > If so, how?
>> > --
>> > Thanks, Jim
>>
>>
>>