Working with Controls on Forms

After you add some fields to your form, you're ready to add controls to your form. You can add text boxes, drop-down combo boxes, check boxes, option buttons, or just about any other valid Windows control to create the right visual look and feel to your form. You can even add images and command buttons that execute code when clicked.

Controls Versus Fields

Many people are confused by the difference between a field and a control. A field is a unit of data. It's the actual data that's displayed on your form; for example, the start date of your appointment. A control is the text box that's used to display the start date. A control on a form is a container for a field. It's very much like the difference between a floppy disk and data. The data is stored on the floppy disk; the disk itself does not hold data unless some is explicitly saved on it.

Adding Controls from the Field Chooser

When you add fields to your form directly from the Field Chooser, you're actually adding a bound control to your form. A bound control is a control that's already associated with a field. When you drag a field from the Field Chooser to the form, a bound control is automatically created. The type of control created depends on the type of field you chose and its format. For example, a text field creates a text box control, and a Yes/No field creates a check box control. Figure 32.8 shows a form with several different types of controls.

Figure 32.8. You can add several different types of controls from the Field Chooser.

graphics/32fig08.jpg

You can create all the controls shown in Figure 32.8 directly from the Field Chooser. When you drag a field onto a form, your control is already bound to the proper field.

Adding Controls to a Form from the Control Toolbox

You can also add controls to your form directly from the control toolbox. To display the control toolbox, choose Form, Control Toolbox to display the toolbox shown in Figure 32.9.

Figure 32.9. The control toolbox enables you to add different types of controls to your form.

graphics/32fig09.gif

Working with the Control Toolbox

By default, the control toolbox contains 14 different controls as well as the control selector (the arrow). The controls are as follows, starting from the top-left corner and going left to right:

  • Select Objects (arrow)

  • Label

  • Text Box

  • ComboBox

  • ListBox

  • CheckBox

  • Option Button

  • Toggle Button

  • Frame

  • Command Button

  • Tab Strip

  • MultiPage

  • ScrollBar

  • Spin Button

  • Image

Adding Controls to the Control Toolbox

A large number of Outlook forms never need any more controls than those listed in the control toolbox. However, if the 14 default controls don't meet your needs, you can add a large number of additional controls to your control toolbox. To add a control, right-click the control toolbox and select Custom Controls to display Figure 32.10.

Figure 32.10. You can add additional controls to your control toolbox.

graphics/32fig10.gif

Scroll through the alphabetical list of available controls to select the controls you need to add to your control toolbox. Check the box next to the control's name to add the control to your toolbox. Selecting any control displays the name and location of the control in the lower section of the Additional Controls dialog box. To see only the controls currently listed in your control toolbox, check the box marked Selected Items Only in the Show section of the dialog box. Figure 32.11 shows the control toolbox with several added controls.

Figure 32.11. You can add numerous different controls to your control toolbox.

graphics/32fig11.gif

You can add as many controls as you want to your control Toolbox, but adding more than five additional controls causes your control toolbox to begin to scroll to display all the controls. You can resize the toolbox by dragging at its borders or you can add an additional tab to your control toolbox to store all your added controls. To add a new tab to your control toolbox, right-click in the gray area next to the word Controls and select New Page. A new page is created with the arrow icon. You can rename the page by right-clicking on the page and selecting Rename. To move controls to your new page, return to the first page and select the control you want to move. Hold down the mouse button and drag the control to the tab of your custom page until the custom page becomes active. Move your mouse down over the custom page (and off the custom page's tab). Release the mouse and your control moves to the new page.

TIP

When adding custom controls to your control toolbox, keep in mind that although these additional controls exist on your machine, they might not exist on the other machines that need to run your custom form. Check with the distributor of your custom control to find out the proper method of distribution of your custom control. Some controls can be freely distributed, whereas others require purchasing a license.


Drawing a Control on a Form

To add any of the controls in the control toolbox to your form, click the desired control. Your mouse pointer will change from an arrow to a plus sign with a small image of the selected control. You can then draw your control on your form. All the default controls can be drawn to fit any size.

Some controls, such as the option button and checkbox controls, come with a built-in label. Other controls, such as the text box, combo box, and list box, do not have included labels. You'll need to add a label separately.

Setting Properties of Controls

After you draw a control on your form, you must customize the control. You can give your control a name, bind it to a field, and set display properties. To configure the properties of your control, right-click it and select Properties to display Figure 32.12.

Figure 32.12. Control the text box control using the Properties dialog box.

graphics/32fig12.gif

If you haven't bound a field to your control or used the Field Chooser to create the control, the first tab of the properties dialog box you see is the Value tab. This tab enables you to select an existing field to bind to your control or create a new field. To select an existing field, click the Choose Field button to display a listing of all available field sets. Move your mouse over a field set and you'll see all available fields in that field set. Click the desired field and the field name, type, format, property, and (sometimes) value are displayed on the Value tab of the Properties dialog box. If you need to create a new field, click the New button to display the dialog box shown in Figure 32.7.

The bottom half of the Value tab enables you to specify an initial value for your field. This ensures that when the form is launched, the field you've created already has a value. You can specify a single value or create a formula for your field. For example, when creating custom forms, you might want to create a custom subject based on the values of certain fields. In the case of a While You Were Out form, you might want the subject to be something like "Lisa Jones Phone Call Urgent" to represent an urgent phone call or message from Lisa Jones. Each of the three pieces of data in the subject could be stored in separate fields. Create three separate fields: ContactName, ItemType, and ItemPriority. All three of these fields can be text fields. After you add these fields to your form, you can right-click the subject control on your form, select Properties, and enter the following in the Initial Value text box on the Value tab: [ContactName] & " " & [ItemType] & " " & [ItemPriority]. Check the box marked Set the Initial Value of This Field To and choose Calculate This Formula Automatically. This will recalculate the subject field every time one of the three fields in the formula is edited. You can perform the same type of operation with any fields on your form. You can use any custom field in your formula calculation. Enclose the field name in brackets within your expression.

Now when your custom form is being used, the item's subject will take the value of your custom fields. For more complicated field values, including calculations, click the Edit button to display Figure 32.13.

Figure 32.13. Create formulas and conditional value statements using this dialog box.

graphics/32fig13.gif

Click the Field button to display the available field sets and choose your field. Choose the Function button to display a list of all available functions. Click OK to save your formula and display it in the Initial Value text box.

TIP

Some fields and formulas should be calculated only when the item is opened for the first time. If you want to have a date field that displays the current date when the custom form is created, choose Calculate This Formula When I Compose a New Form. This updates the value of the field only when you create a new form, not when you open an existing form. Otherwise, choose Calculate This Formula Automatically.


graphics/troubleshoot_icon.jpg

If you've created a date field to contain the creation date of the form and tried to set the Initial Value to Now and the calculation interval to Calculate this formula when I compose a new form, and can't maintain the creation date of the form once a saved form has been forwarded or replied to, see "My Date Keeps Changing" in the "Troubleshooting" section at the end of the chapter.


After you create a field to bind to your control, you can configure additional information about your control including font, size, and other advanced properties. Click the Display tab in the Properties dialog box to display Figure 32.14.

Figure 32.14. The Display tab enables you to configure font information.

graphics/32fig14.gif

You can change the name of your control from this page. Changing the name of your control does not affect the name of the field on the form. The control name is important when configuring tab order and when enabling or disabling a control within a form. If you use the control toolbox to create a control, the control will be named something very generic, such as TextBox2. This doesn't provide you with very much information about the control. Consider renaming your control either to match the name of the field or at least reference the name of the field. Naming a text box control WhoCalled when the field name is ContactName could be a close enough match for you. However, you'll probably encounter less confusion if you name your control similarly to your field.

TIP

If you're viewing the properties of a label control, checkbox control, or option button control, you can also change the caption of the control directly in the Properties dialog box.


The Position section of the Display tab enables you to alter the position of the control on your form. The numbers are calculated in pixels. If you're creating a series of text boxes and want them all to be left-aligned, you can edit the left pixel value to force them to all match.

The next section of the display tab allows you to configure font information. You can change the font size, font name, and font color by clicking the Font button to display Figure 32.15. Click OK when you have finished setting your font to return to the Display tab of the Properties dialog box.

Figure 32.15. Change the size, color, and font used to display the control.

graphics/32fig15.gif

You can also change the foreground and background color of your control by selecting a color from the appropriate list box. Use the Settings section to further customize your control. Sometimes you might want to make a control read only for display purposes. Just check the Read Only box in the Settings section.

Creating and Using Validation Rules

The last tab in the Properties dialog box is the Validation tab, shown in Figure 32.16. This tab enables you to control the field bound to the control. Validation rules and checks are triggered when the form is posted or sent.

Figure 32.16. Use the Validation tab to ensure that your field contains accurate data.

graphics/32fig16.gif

If you want to require a value for the field, check the box marked A Value Is Required for This Field. If this box is checked and you don't enter a value for the field, Outlook informs you that you must enter a value. Unfortunately, the message you receive when you attempt to submit a form that has a field with a validation rule is very cryptic. If you don't enter a validation message, you'll receive only the message A field on this form requires a value. It's up to you to deduce which field requires the value.

TIP

If you want a more detailed error message when a required field doesn't have a value, consider writing code to perform the validation.


It's also possible to require a specific type of data in your field through validation. For example, if you have a field in your form that requires a number greater than 10, you can test for this condition using a validation rule. To enter a validation rule, use the following steps:

  1. Check the box marked Validate This Field Before Closing the Form.

  2. Click the Edit button for the Validation Formula text box.

  3. Enter your validation formula. An example of a field that requires a number greater than 10 is shown in Figure 32.17.

    Figure 32.17. A validation formula to require a number greater than 10.

    graphics/32fig17.gif

  4. Click OK to save your formula.

  5. You don't need to enter a message to let users know that their validation formula has failed, but it's a good idea to let them know what they're doing wrong. To enter a message that lets users know validation has failed, type the validation message in the box marked Display This Message If the Validation Fails.

  6. If you want to enter a detailed validation message, you can click the Edit button. From this window, which is almost identical to Figure 32.17, you can enter a detailed validation message. For instance, it might be helpful to enter a validation message that tells the user You have entered a value of 3 for the Multiple field. Please enter a value greater than 10. This validation message is displayed in Figure 32.18.

    Figure 32.18. You can display a very detailed validation message.

    graphics/32fig18.gif

  7. Click OK or Apply to save your changes and apply your validation rule.

The last option on this page is the check box marked Include This Field for Printing and Save As. Checking this box ensures that your field is displayed when the form is printed. This option is checked by default.

Click OK or Apply to save your changes and return to your form.

Adding an Image Control to a Form

The previous sections explained how to add various controls to your Outlook 2003 form. You can add text boxes, combo boxes, labels, frames, command buttons, check boxes, and option buttons. Another popular control that needs special mention is the image control.

The image control is designed to display a graphic in a variety of formats, including JPG, GIF, and ICO. You can add a company logo to your form or an image of a product. The image can be stored anywhere on your hard drive, floppy disk, or network drive. When you add the image to the image control that image is stored within the form. To add an image to, your form, first add an image control from the control toolbox. If you know the approximate size of the image you want to add to the control, try to size your control to that size. You can always resize it later. To select the image for your control, perform the following steps:

  1. Right-click on the control and select Advanced Properties to display Figure 32.19.

    Figure 32.19. Use the advanced Properties dialog box to configure the image for your control.

    graphics/32fig19.gif

  2. Click the Picture line in the advanced Properties dialog box.

  3. Click on the ellipses (…) next to the Apply box to display the Load Picture dialog box shown in Figure 32.20.

    Figure 32.20. Select the picture to use with your image control.

    graphics/32fig20.gif

  4. After you select your picture, click Open to return to the advanced Properties dialog box.

  5. Next, select the mode of the picture.

    • Clip mode shows only the amount of your picture that can fit in the image control.

    • Stretch mode resizes your picture to fit within the bounds of the Image control.

    • Zoom mode resizes your picture to fit within the bounds of the image control but keeps the original proportions of the picture. This can result in some gray space between your image and the edges of the image control.

  6. When you are done editing the properties of your image control, close the advanced Properties dialog box and return to your form.



Special Edition Using Microsoft Office Outlook 2003
Special Edition Using Microsoft Office Outlook 2003
ISBN: 0789729563
EAN: 2147483647
Year: 2003
Pages: 426

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