>
DefaultValue Property
Applies To
Field Object.
Description
Sets or returns the default value of a Field object. For a Field object not yet appended to the Fields collection, this property is read/write.
Settings and Return Values
The setting or return value for this property is a string expression, which can contain a maximum of 255 characters. It can be either text or an expression. If the property setting is an expression, it can't contain user-defined functions; Microsoft Jet database engine SQL aggregate functions; or references to queries, forms, or other Field objects.
Note
You can also set the DefaultValue property of a Field object on a TableDef object to a special value called "GenUniqueId( )". This causes a random number to be assigned to this field whenever a new record is added or created. The field's Type property must be Long.
Remarks
Use of the DefaultValue property depends on the parent object of the Field objects, as shown in the following table.
Object appended to | Usage |
|
Index | Not supported |
QueryDef | Read-only |
Recordset | Read-only |
Relation | Not supported |
TableDef | Read/write |
When a new record is created, the DefaultValue property setting is automatically entered as the value for the field. You can change the field value by setting its Value property.
The DefaultValue property doesn't apply to Counter and OLE Object fields.
See Also
AllowZeroLength Property, QueryDef Object, Required Property, TableDef Object, ValidateOnSet Property, ValidationRule Property, ValidationText Property, Value Property.
Specifics (Microsoft Access)
If the DefaultValue property setting is an expression, it can't contain user-defined functions, Microsoft Access domain aggregate functions, SQL aggregate functions, the CurrentUser function, the Eval function, or references to queries, forms, or other Field objects.
Example (Microsoft Access)
The following example creates a new Field object and sets its DefaultValue property. The procedure then appends the new object to the Fields collection of the Employees table in the TableDefs collection of the database.
Sub NewField()
Dim dbs As Database, tdf As TableDef
Dim fld As Field
' Return Database object that points to current database.
Set dbs = CurrentDb
' Return TableDef variable pointing to Employees table.
Set tdf = dbs.TableDefs!Employees
' Create Field object.
Set fld = tdf.CreateField("DaysOfVacation", dbText, 20)
' Set field properties.
fld.DefaultValue = "10"
' Append fld to Fields collection.
tdf.Fields.Append fld
End Sub