DefaultValue Property

Applies To

Check Box Control, Combo Box Control, List Box Control, Option Button Control, Option Group Control, Table Fields, Text Box Control, Toggle Button Control.

Description

You can use the DefaultValue property to specify a value that is automatically entered in a field when a new record is created. For example, in an Addresses table you can set the default value for the City field to New York. When users add a record to the table, they can either accept this value or enter the name of a different city.

Notes

  • The DefaultValue property doesn’t apply to check box, option button, or toggle button controls when contained in an option group. It does apply to the option group itself.
  • The DefaultValue property applies to all table fields except those fields with the data type of AutoNumber or OLE Object.

Setting

The DefaultValue property specifies text or an expression that is automatically entered in a field when a new record is created. For example, if you set the DefaultValue property for a text box control to = Now(), the control displays the current time. The maximum length for a DefaultValue property setting is 255 characters.

You can set this property in the property sheet in table Design view (under Field Properties), a macro, or Visual Basic.

In Visual Basic, use a string expression to set the value of this property. For example, the following sets the DefaultValue property for a text box control named PaymentMethod to “Cash”.


Forms!frmInvoice!PaymentMethod.DefaultValue = """Cash"""

Note To set this property for a field using Visual Basic, use the Data Access Objects DefaultValue property.

Remarks

If you create a control by dragging a field from the field list, the field’s DefaultValue property setting, as defined in the table, is applied to the control on the form.

One control can provide the default value for another control. For example, if you set the DefaultValue property for a control to the following expression, the field’s default value is set to the DefaultValue property setting for the txtShipTo control.


= Forms![frmInvoice]![txtShipTo]

If the controls are on the same form, the control that is the source of the default value must appear earlier in the tab order than the control containing the expression.

The DefaultValue property is applied only when you add a new record. If you change the DefaultValue property, the change is not automatically applied to existing records.

If you set the DefaultValue property for a control on a form for a field that also has a DefaultValue property setting defined in the table, the control setting overrides the table setting.

See Also

AllowZeroLength Property, DefaultValue Property (Microsoft Office 95 Data Access Reference), Required Property, Value Property.