The Required Property: Making the User Enter a Value
The Required
property is very important: It determines whether you require a user to
enter a value in a field. This property is useful for foreign key
fields, when you want to make sure the user enters data into the field.
It’s also useful for any field containing information that’s needed for
business reasons (company name, for example).
A foreign key field
is a field that is looked up in another table. For example, in the case
of a Customers table and an Orders table, both might contain a
CustomerID field. In the Customers table, the CustomerID field is the
primary key field. In the Orders table, the CustomerID field is the
foreign key field because its value is looked up in the Customers table.
|
Set the Required Property from Design View
To designate a field as required (from Design view), follow these steps:
1. | Select the desired field.
|
2. | Click the Required text box in the Field Properties pane.
|
3. | Type Yes.
|
The Allow Zero Length Property: Accommodating for Situations with Nonexistent Data
You can use the Allow Zero Length property
to allow a string of no characters. You enter a zero-length string by
typing a pair of quotation marks with no space between them (””). You use the Allow Zero Length property to indicate that you know there is no value for a field.
Set the Allow Zero Length Property from Design View
To allow a zero-length field (from Design view), follow these steps:
1. | Select the desired field.
|
2. | Click the Allow Zero Length text box in the Field Properties pane. |
3. | Select Yes from the drop-down list box.
|
The Input Mask Property: Determining What Data Goes into a Field
An input mask controls data the user enters into a field. For instance, a short date input mask appears as --/--/---- when the field is active. You can then simply type 07042005 to display or print 7/4/2005. Based on the input mask, you can ensure that the user enters only valid characters into the field.
Table 3 lists some of the placeholders that you can use in character strings for input masks in fields of the Text data type.
Table 3. Placeholders That Can Be Included in an Input Mask
Placeholder | Description |
---|
0 | A number (0–9) is required. |
9 | A number (0–9) is optional. |
# | A number (0–9), a space, or a plus or minus sign is optional; a space is used if no number is entered. |
L | A letter (A–Z) is required. |
? | A letter (A–Z) is not required; a space is used if no letter is entered. |
A | A letter (A–Z) or number (0–9) is required. |
A | A letter (A–Z) or number (0–9) is optional. |
& | Any character or space is required. |
C | Any character or space is optional. |
> | Any characters to the right are converted to uppercase. |
< | All the text characters to the right are changed to lowercase. |
Set the Input Mask Property from Design View
To create an input mask (from Design view), follow these steps:
1. | Select the desired field.
|
2. | Click the Input Mask text box.
|
3. | Type the desired format, using the placeholders listed in Table 3.
|
Access includes an Input Mask Wizard that appears
when you place the cursor in the Input Mask text box and click the
build button to the right of the text box. The wizard, shown in Figure 2,
provides common input mask formats from which to choose. To start the
Input Mask Wizard, you click the button to the right of the Input Mask property.
The Input Mask Wizard is available only if you
selected the Additional Wizards component during Access setup. If you
did not select this component and then you try to open the Input Mask
Wizard, Access prompts you to install the option on-the-fly the first
time you use it.
|
For example, the input mask 000-00-0000;;_ (converted to 000\-00\-0000;;_
as soon as you tab away from the property) forces the entry of a valid
social security number. Everything that precedes the first semicolon
designates the actual mask. The zeros force the entry of the digits 0
through 9. The dashes are literals that appear within the control as
the user enters data. The character you enter between the first and
second semicolon determines whether literal characters (the dashes, in
this case) are stored in the field. If you enter a 0 in this position,
literal characters are stored in the field; if you enter 1 or leave
this position blank, the literal characters aren’t stored. The final
position (after the second semicolon) indicates what character is
displayed to denote the space where the user types the next character
(in this case, the underscore).
Here’s a more detailed example: In the mask \(999”) “000\-0000;;_,
the first backslash causes the character that follows it (the open
parenthesis) to be displayed as a literal. The three nines allow the
user to enter optional numbers or spaces. Access displays the close parenthesis and space within the quotation marks as literals. The first three zeros require values 0 through 9.
The dash that follows the next backslash is displayed as a literal.
Four additional numbers are then required. The two semicolons have
nothing between them, so the literal characters aren’t stored in the
field. The second semicolon is followed by an underscore, so an
underscore is displayed to indicate the space where the user types the
next character. This sounds pretty complicated, but here’s how it
works. The user types 8054857632. What appears is (805)485-7632. What is actually stored is 8054857632.
Because the input mask contains three nines for the area code, the area
code is not required. The remaining characters are all required numbers.