L Team LiB |
Creating Custom Forms
Although the standard Outlook forms are often good enough, there are times when you'll wish the form had different fields You might want to remove some of the default fields, add some of your own, or just rearrange what's there
You might want to create a boilerplate message to use 1n response to inquiries, or pre- address a message form to a group of people with whom you often correspond You can do all of this and more using custom forms
You can create templates and forms containing boilerplate text by editing the fields in the form But when you want to add or remove fields or use scripting with the form, you need to use Design mode to open Outlook forms so that they can be edited
You don't need a special program to use Design mode; it's part of every form included with Outlook and is enabled when you tell Outlook you want to design a form
You can open a form in Design mode two ways: by using Tools, Forms, Design a Form and selecting a form from the dialog; or when a form is already open, by using its Tools, Forms, Design this Form menu option In any case, when it's a message form, it will look similar to Figure 20.1
Figure 20.1 A message form in Design mode Hidden pages have parentheses around their names Drag fields from the Field Chooser to add them to a form or
Trang 2You need to use Outlook as your email editor to design email forms or templates When Word is your editor, you can't go into Design mode for email forms
When forms are in Design mode, the Form Design toolbar is visible (see Figure 20.2) This toolbar has many of the design tools you'll use the most The Form and Layout menus also contain design tools
Trang 3Customize the Forms toolbar to add the Run This Form button to it Doing so makes it easier to test your forms as you design them
Along with the Form Design toolbar, you'll also use the Field Chooser and Control Toolbox to create your custom forms Right-click on any control to access the Properties and Advanced Properties dialogs The Properties dialog contains display, value, and validation information for the control, whereas Advanced Properties has more advanced display properties
To design forms, drag controls from the Control Toolbox or fields from the Field
Chooser and configure the properties Select the control and drag it to the form, dropping the control when the mouse cursor is over the area where you want the control placed When you drag fields to the form, the fields are automatically arranged on the left edge of the form
A feature many people request is to list a person's age on the contact form, so I'll show you how to create a custom form with the contact's age on it
Task: Design a Form
Designing a custom form is actually pretty easy, at least for simple forms You can customize any Outlook form, except for message forms, when you use Word as the editor
1 Open the Design Form dialog using the Tools, Forms, Design a Form Menu (see Figure 20.3) The Standard form library contains the form types that can be customized
Trang 4Outlook's notes, known in form language as IPM.StickyNote, are not customizable and can't be used for custom forms You can save notes to use as templates
2 Select a form to edit or customize For this example, I'm going to choose a contact form to open (see Figure 20.4)
Trang 5The first page of each of the appointment, journal, and task forms is not customizable The All Fields, Properties, and Actions tabs are not customizable on any form
Editable pages have a grid to help you align the controls and page names in parentheses indicate that the page is hidden on published forms
The Field Chooser lists all available fields that can be used on the forms and displays when a form opens in Design mode You can create new fields if you need them (click the New button)
Trang 63 Our age form uses a TextBox to display a formula that calculates a person's age, so we need to choose the Control Toolbox button to display the controls
Because I like the contact form with the picture control, I'm going to add the Age field to (P.2) When the first control is dropped on the page, the parentheses disappear
4 Drag a Label and a TextBox control to the form These are the second and third icons in the Control Toolbox, identified by the uppercase A icon and the lowercase ab icon
5 Right-click on the control identified as Labell and choose Properties (see Figure
20.5)
Figure 20.5 Change the properties of a control using the Properties sheet In this case, we're leaving the label named Labell and changing the caption to
Current Age
You can change other properties, such as the font and colors Because this field is used as the name for the TextBox, we don't need to change anything on the other tabs
Trang 7and select the Value tab Click New to create a new field for Age, using Number for the Type: and changing Format: to All Digits (see Figure 20.6)
Figure 20.6 Create a new field for displaying the age
Trang 811.Choose Calculate This Formula Automatically and click the Value tab Select the Validation tab and add a check to Include This Field for Printing and Save As Click OK
A less accurate, but easier to type formula is (Now( - [Birthday] ) /365 This formula rounds to the contact's nearest birthday, with the age off by as much as six months
Now it's time to test your form Choose Form, Run This Form to open a new form using your new form Enter | test in the File As Field, select the Details tab, and type your birth date in the Birthday field Save the form using File, Save (Ctrl+S) and check the Age field
You could add this to an appointment form that you use for birthdays and anniversaries
Does it show your age as of your last birthday? If the age is correct, congratulations: You created your first custom form If the age is not correct, check the formula for
typographical errors If you want to copy the formula and paste it into the field, the formula and sample forms are at http://www.outlook-tips.net/samples.htm
Trang 9The new page uses an ugly gray color You can change this by right-clicking on the Current Age label and choosing Advanced Properties Select the BackColor field, type OOf7f7f7 in the text box at the top of the form, and then click Apply, as shown in Figure 20.6 This changes the label field to the silver color used on the other pages You can double-click on the BackColor property to open the color picker, if you want to use a different color
Click again anywhere on the page to switch to the Properties dialog for the page (see Figure 20.8) Change the BackColor property to OOf7f7f7, apply it, and close the Properties dialog
Figure 20.8 Use the Advanced Properties dialog to change the display properties for the control
The final step before saving the form is entering a version number This helps to prevent corruption in the forms cache when you increment the version number after editing the form and republishing it using the same name
When you don't use a version number and republish the form, you might cause the form to become one-offed One-offed means that the form uses a form definition stored with the form, not the global definition This results in larger item sizes and the possibility of mismatched fields
Trang 10Although it's not necessary, you can also select custom icons to use for the large and small icons Choose a 32x32 icon for each size, with the large icon filling the 32x32 square and the small icon using a 16x16 image in the upper-left corner
Custom icons usually won't be visible on forms in your Outlook folders until you restart Outlook Occasionally, you'll also need to delete
C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\ FORMS\FRMCACHE.DAT before the icons will be visible
If you can't find the folder, you have hidden files and folders enabled Use Search and enable Search Hidden Files and Folders under More Advanced Options
The other options you can configure on the dialog include password protecting the form so that others can't customize it and sending the form definition with the item
Check Send Form Definition when you are creating a form you're going to share with other people, or when you use Exchange Server and didn't publish the form to the
Organizational Forms library When it's enabled, the complete form is sent, resulting in a larger item but enabling the recipient to see and use your customizations If you don't send the form definition, Outlook uses the default form to display the item
Although you can create many nice custom forms using only controls and fields, at some point you might need code to do what you want the form to do You'll need to know how to write VBScript, or at least know where to find code samples on the Internet
Task: Add a VB Script to a Form
I'm going to customize another contact form, this time with a command button that enables you to add the time and date to the Notes field
1 Open anew contact form in Design mode and click on the Control Toolbox toolbar button to display the toolbox
2 Drag the CommandButton control to an empty area on the form I'm putting it under the Address fields on my form (see Figure 20.9)
Trang 11œ mm 9 10 11
Right-click on the button and choose Properties Enter a descriptive caption in the Caption field and click OK
Choose Form, View Code to open the Script Editor Enter the following script in the editor then click on the X to close the window: Sub StampDate() Item.Body = Now() & vbCrLf & vbCrLf & Item.Body End Sub Sub CommandButton1_Click() Call StampDate() End Sub
Choose Form, Run This Form to test your code Pressing the command button should enter the current time and date
You'll find it's easier to use a third-party script editor or the Visual Basic IDE when you're working with complex scripts You'll have better tools to verify your code and can copy and paste the finished script into the Script Editor window
Because the form contains code, it must be published Outlook's security prevents the code from running