Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

 
 
Microsoft Office Access
Search
Search
 
Check for updates: (c) Microsoft
Office downloads
 
 
 
Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Email this linkEmail this link Printer-Friendly VersionPrinter-Friendly Version Bookmark and ShareShare
DefaultValue Property
 

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 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.

advertisement