Field.DefaultValue Property
Access Developer Reference |
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 (Microsoft Access workspaces only).
Syntax
expression.DefaultValue
expression A variable that represents a Field object.
Remarks
The setting or return value is a String data type that 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 Access 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, thereby giving each record a unique identifier. The field's Type property must be Long. |
The availability of the DefaultValue property depends on the object that contains the Fields collection, as shown in the following table.
If the Fields collection belongs to an | Then DefaultValue is |
---|---|
Index object | Not supported |
QueryDef object | Read-only |
Recordset object | Read-only |
Relation object | Not supported |
TableDef object | 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 AutoNumber and Long Binary fields.
Example
This example uses the DefaultValue property to alert the user of a field's normal value while prompting for input. In addition, it demonstrates how new records will be filled using DefaultValue in the absence of any other input. The DefaultPrompt function is required for this procedure to run.
Visual Basic for Applications |
---|
|