Set Initial Field Values

When you create an initial value for a field, you specify the values that are available in the field when the user opens the form to create a new item. With Outlook, the way the initial value is set varies somewhat depending on the control to which the field is bound. As a result, we'll cover the general concept of initial values in this section and then cover how to set initial values for each control separately.

Figure 6.10 - The TotalDays field calculates the difference between the StartDate and EndDate fields and adds 1. Here are a few examples of why you set initial values for fields.

® To set the default values in Label, TextBox, ComboBox, ListBox, CheckBox, and OptionButton controls.

® To set the initial value of the Subject field of a form to summarize the content of the form. For example, for an Art Approval form, you can set the initial value of the Subject field to Art Approval.

® To set the initial value of the To field on a Message form to preaddress the form. For example, for an Employee Feedback form, you can preaddress the To field to an Employee Feedback public folder so that all responses are automatically routed to that folder.

The following table lists the sections in this chapter that explain how to set initial values for the control to which the field is bound. Therefore, each control contains a separate section on how to set the initial value.

To Set the Initial Value For A

See Later in This Chapter

To field

To Field

Subject field

Subject Field

Message field

Message Field

Field bound to a Label control

Label Controls

Field bound to a TextBox control

TextBox Controls

Field bound to an OptionButton control

OptionButton Controls

Field bound to a CheckBox control

CheckBox Controls

Field bound to a ComboBox control

ComboBox Controls

Field bound to a ListBox control

ListBox Controls

Validate and Restrict Data

Outlook provides a couple of ways to validate and control how information is entered into a form.

* At the simplest level, you can specify that a value is required for a field. As a result, if the user tries to submit or save the item and no value is in the field, a message box appears, saying that a value is required in the field.

* You can create a validation formula for a field. If the field validation fails, a message box appears, showing the types of values allowed in the field. Specify That a Value Is Required for a Field

Many forms contain Text fields in which the user is required to enter information. For example, on the Business Card Request form, as shown in Figure 6-11, the Name field requires a value. If a value is not entered in the Name field when the user attempts to send the form, Outlook shows a message box that tells the user that a field on the form requires a value.

To specify that a value is required for a text field

1. Right-click the control that is bound to the field, and then click Properties on the shortcut menu.

2. Click the Validation tab.

3. Select the A Value Is Required For This Field check box.

Figure 6.11 -On the Business Card Request form, a value is required in the Title field. If no value is entered, users see a message when they attempt to send the

Many of the Outlook field types automatically supply a value In the field by default. For example, the Date field has the value None by default. For field types such as Date, Currency, and Number that automatically supply a value, you must create a formula or use a script to validate that the field contains the specified Information.

Create Validation Formulas

Outlook performs field validation when users attempt to save, send, or post an Item. In addition, Outlook performs field validation when users attempt to close a form. With validation formulas, you can limit the type of Information that can be saved to the Item. For example, you can define

as the validation formula for a Number field that accepts only values from 10 to 100. When users attempt to submit or save the Item, they see a message only If the number entered In the field does not fall within the range of 10 to 100.

If you want to validate the field Immediately after users enter Information In the field, you can do so by writing VBScript code for your form and using the PropertyChange event or CustomPropertyChange event. For more Information, see Chapter 11. "Using Visual Basic, VBA, or VBScript with Outlook."

To create a validation formula

1. Right-click the control you want to create a validation expression for, and then click Properties on the shortcut menu.

2. Click the Validation tab, and then, under Validation Formula, click the Edit button.

3. Type the validation formula or use the Field or Function button to build the formula, and then click OK.

4. In the DIsplayThls Message If The Validation Falls text box, type the message you want to appear In the message box the user will see If the validation falls.

Formulas That Validate Amounts

For many forms, you can create field validation formulas to check whether a value In the field Is more or less than a specified value. For example, In Figure 6-12, the validation formula for the Amount field In the Charity Donation form specifies that the value In the field must be at least $1. If the user enters a value less than $1 In the Amount field, a message appears.

Note that the CCurfunctlon (Currency Conversion) Is used In the validation formula. For more Information on the CCurfunctlon, see Microsoft Visual Basic Help.

Validation Formulas That Compare One Field Value with Another

In some cases, you might want to create a validation formula that compares one field value against another field value. For example, for the Vacation Request form shown In Figure 6-13, the value of the StartDate field Is compared with the value of the EndDate field to make sure the EndDate value falls after the StartDate value.

Figure 6.12 - The Amount field contains a value that is less than one dollar. When the user attempts to send the form, a message box appears, indicating what is acceptable in the field.

Validation formulas can sometimes cause unexpected results in your forms. If you delete a bound control that uses a validation formula but then fail to delete the underlying user-defined field in the folder, you may experience validation messages that don't appear to have a source. Normally, the focus changes to the control that has triggered the validation error. However, if the control is not on the form page that has the focus, the user will not be able to determine which field value is causing the error. Writing VBScript code to control validation is more difficult than using validation formulas, but it can lead to a more consistent experience for your users, and it can accommodate more complex validation scenarios.

Figure 6.13 - The validation formula for the EndDate field specifies that the validation passes if the value is greater than the StartDate field.

Was this article helpful?

0 0

Post a comment