6.4. Setting the Default Value of a Control

When a control is based on a field from a data source, there are some cases when you want to have a value put in the control automatically when new records are added. This value is called the default value. In a perfect world the default value of a field is specified for the field in the table, located in the database. However, there will be times when it is overlooked, or you want to override the default value set at the database level.

Which type of data you will use as a default value will depend on the data type of the field. The following table displays some example of default values that could be used with the form used in this chapter:

FieldDefault ValueDescription
Region"WA"Places the abbreviation for the state of WA in the Region field.
Order Datetoday()Use the today() formula to assign today's date.
Quantity1Setting a numeric value to 1 or 0; this helps to keep users from leaving values blank.

When set at the form level, default values are just like other values you enter into forms in that you need to click the Submit button to have them saved in the database.

6.4.1. Using Literal Values

The way to specify default values is to use the property sheet of the control. There are several ways to specify default values. The first way is enter the value you want into the Value entry in the Default Value area on the data tab of the property sheet.

6.4.1.1. Try It Out: Adding a Default Value to Quantity

Using the Chapter 6 Starting.xsn ...

Get Beginning InfoPath™ 2003 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.