Setting Default Values of Fields

Access assigns Number and Currency fields a default value of 0; all other field types are empty by default. (Notice that the tentative append record in Figure 5.22 has zeros entered in all the Number and Currency fields.) You can save data-entry time by establishing default values for fields; in some cases, Access's default values for Number and Currency fields might be inappropriate, and you must change them. Table 5.9 lists the default values you should enter for the HRActions table's fields.

Table 5.9. Default Field Values for the HRActions Table

Field Name

Default Value

Comments

EmployeeID

Null

0 is not a valid Employee ID number, so you should remove Access's default.

ActionType

Q

Quarterly performance reviews are the most common personnel action.

InitiatedBy

Null

0 is not a valid Employee ID number.

ScheduledDate

=Date()

This expression enters today's date from the computer system's clock.

ApprovedBy

Null

0 is not a valid Employee ID.

EffectiveDate

=Date()+28

This expression enters today's date plus four weeks.

HRRating

Null

In many cases, a rating doesn't apply. A 0 rating is reserved for terminated employees.

NewSalary

Null

If a salary, hourly rate, bonus, or commission has no change, no entry should appear. 0 would indicate no salary, for example.

NewRate

  

NewBonus

  

NewCommission

  

HRComments

No Entry

Access's default is adequate.

If you don't enter anything in the Default Value text box, you create a Null default value. It's a better database design practice to be explicit when overriding default values, so you replace 0 values with Null. You can use Null values for testing whether a value has been entered into a field. Such a test can ensure that users have entered required data.

You use expressions, such as =Date()+28 to enter values in fields, make calculations, and perform other useful duties, such as validating data entries. Expressions are discussed briefly in the next section and in much greater detail in Chapter 10, "Understanding Jet Operators and Expressions." An equal sign must precede expressions that establish default values.

To assign the new default values from those of Table 5.9 to the fields of the HRActions table, complete these steps:

  1. graphics/design_view.gif Click the View button of the Datasheet toolbar. Access selects the first field of the table.

  2. Press F6 to switch to the Field Properties window, move the caret to the Default Value text box, and type Null for the default value of the EmployeeID field.

  3. Press F6 to switch back to the Table Design grid. Move to the next field and press F6 again.

  4. Add the default values for the 10 remaining fields having the default entries shown in Table 5.9, repeating steps 1 through 3. For example, after selecting the Default Value text box for the ActionType field, type Q to set the default value; Access automatically surrounds Q with double quotes.

  5. graphics/datasheet_view.gif After completing your default entries, click the View button of the Table Design toolbar, and click Yes when asked if you want to save the table. The HRActions table appears in Datasheet view with the new default entries you assigned (see Figure 5.23).

    Figure 5.23. Datasheet view of the HRActions table confirms the changes you make to the Default Value property of the fields.

    graphics/05fig23.gif

graphics/power_tools.gif

The Nwind05.mdb database in the \Seua11\Chaptr05 folder of the accompanying CD-ROM includes the HRActions table, which you can import into Northwind.mdb.



Special Edition Using Microsoft Office Access 2003
Special Edition Using Microsoft Office Access 2003
ISBN: 0789729520
EAN: 2147483647
Year: 2005
Pages: 417

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net