Applies to
| CheckBox Object
|
OptionGroup Object
|
| ComboBox Object
|
TextBox Object
|
| ListBox Object
|
ToggleButton Object |
| OptionButton Object
|
|
Specifies a String 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. Read/write.
expression.DefaultValue
expression Required. An expression that returns one of the objects in the Applies To list.
Remarks
- The DefaultValue property doesn't apply to check box (check box: A control that indicates whether an option is selected. A check mark appears in the box when the option is selected.), option button (option button: A control, also called a radio button, that is typically used as part of an option group to present alternatives on a form, report, or data access page. The user cannot select more than one option.), or toggle button (toggle button: A control that is used to provide on/off options on a form or report. It can display either text or a picture and can be stand-alone or part of an option group.)
controls (control: A graphical user interface object, such as a text box, check box, scroll bar, or command button, that lets users control the program. You use controls to display data or choices, perform an action, or make the user interface easier to read.) when they are in an option group (option group: A frame that can contain check boxes, toggle buttons, and option buttons on a form, report, or data access page. You use an option group to present alternatives from which the user can select a single option.). It does however apply to the option group itself.
- The DefaultValue property applies to all table fields except those fields with the data type of AutoNumber (AutoNumber data type: In a Microsoft Access database, a field data type that automatically stores a unique number for each record as it's added to a table. Three kinds of numbers can be generated: sequential, random, and Replication ID.) or OLE Object (OLE Object data type: A field data type that you use for objects created in other applications that can be linked or embedded (inserted) in an Access database.).
The DefaultValue property specifies text or an expression (expression: A combination of operators, field names, functions, literals, and constants that evaluates to a single value. Expressions can specify criteria (such as Order Amount>10000) or perform calculations on field values (such as Price*Quantity).) that's automatically entered in a control or field when a new record is created. For example, if you set the DefaultValue property for a text box (text box: A control, also called an edit field, that is used on a form, report, or data access page to display text or accept data entry. It can have a label attached to it.) control to =Now(), the control displays the current date and time. The maximum length for a DefaultValue property setting is 255 characters.
For a control, you can set this property in the control's property sheet (property sheet: A window that is used to view or modify the properties of various objects such as tables, queries, fields, forms, reports, data access pages, and controls.). For a field, you can set this property in table Design view (Design view: A window that shows the design of these database objects: tables, queries, forms, reports, macros, and data access pages. In Design view, you can create new database objects and modify the design of existing ones.) (in the Field Properties section), in a macro (macro: An action or set of actions that you can use to automate tasks.)
, or by using Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) code.
In VBA code, use a string expression (string expression: An expression that evaluates to a sequence of contiguous characters. Elements of the expression can be: functions that return a string or a string Variant (VarType 8); a string literal, constant, variable, or Variant.) to set the value of this property. For example, the following code 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 by using VBA code, use the ADO DefaultValue property or the DAO DefaultValue property.
The DefaultValue property is applied only when you add a new record. If you change the DefaultValue property, the change isn't automatically applied to existing records.
If you set the DefaultValue property for a form control that's bound to a field that also has a DefaultValue property setting defined in the table, the control setting overrides the table setting.
If you create a control by dragging a field from the field list (field list: A window that lists all the fields in the underlying record source or database object, except in data access page Design view. In data access page Design view, it lists all the record sources and their fields in the underlying database.), the field's DefaultValue property setting, as defined in the table, is applied to the control on the form although the control's DefaultValue property setting will remain blank.
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 control'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 (tab order: The order in which the focus moves in a form from one field or object to the next as you press TAB or SHIFT+TAB.) than the control containing the expression.