|
Chapter 6: Keeping Your Information Accurate continued
Using the Data Type to Restrict DataThe Data Type setting restricts entries to a specific type of data: text, numbers, dates, and so on. If, for example, the data type is set to Number and you attempt to enter text, Access refuses the entry and displays a warning.In this exercise, you will create a brand new database, you will add fields of the most common data types, and then you’ll experiment to see how the Data Type setting and Field Size property can be used to restrict the data entered into a table. The working folder for this exercise is SBS\Access\Accurate\DataType. Follow these steps:
If the New File task pane is not displayed, click the New button on the toolbar.
Access opens the database window for the new database.
A blank Table window opens in Design view so that you can define the fields that categorize the information in the table. You will define five fields, one for each of the Text, Number, Date/Time, Currency, and Yes/No data types.
TIP: The data type referred to as Yes/No in Access is more commonly called Boolean (in honor of George Boole, an early mathematician and logistician). This data type can hold either of two mutually exclusive values, often expressed as yes/no, 1/0, on/off, or true/false.
Access displays a dialog box recommending that you create a primary key.
Your table now looks like the one on the next page. The properties for the selected field are displayed in the lower portion of the dialog box.
The data type for this field is Number. Access displays an alert box refusing your text entry.
The date field accepts almost any entry that can be recognized as a date, and displays it in the default date format. Depending on the format on your computer, Jan 1 might be displayed as 1/1/2001 or 1/1/01.
TIP: If you enter a month and day but no year in a date field, Access assumes the date is in the current year. If you enter a month, day, and two-digit year from 00 through 29, Access assumes the year is 2000 through 2029. If you enter a two-digit year that is greater than 29, Access assumes you mean 1930 through 1999.
Access stores the number you entered but displays ($45.35), the default format for displaying negative currency numbers.
TIP: Access uses the regional settings in Microsoft Windows Control Panel to determine the display format for date, time, currency, and other numbers. If you intend to share database files with people in other countries, you might want to create custom formats to ensure that the correct currency symbol is always displayed with your values. Otherwise, the numbers won’t change, but displaying them as dollars, pounds, marks, or lira will radically alter their value.
This field won’t accept anything you type; it only allows you to switch between two predefined values. Your datasheet now resembles the one shown on the next page.
TIP: In Design view, you can use properties on the Lookup tab to display the Boolean field as a check box, text box, or combo box. You can also set the Format property on the General tab to use True/False, Yes/No, or On/Off as the displayed values in this field (though the stored values will always be -1 and 0).
Last Updated: Saturday, July 7, 2001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||