Fields

[Previous] [Next]

Fields are named variables where Outlook stores the data for your application. A number of built-in fields store default information. These built-in fields are associated with folders and their default content type. For example, in a Contacts folder, built-in fields include First Name, Last Name, Mailing Address, and Primary Phone. In your Inbox, built-in fields include From, To, Subject, and Message. Outlook also supports Office document properties as fields. For more information on using Office document properties as fields, see the section titled "Extending Functionality with Office Document Forms" in Chapter 4.

Outlook provides an extensive amount of built-in fields, but there will be many times when you need to add custom fields for your application. Outlook fully supports this capability and allows you to add custom fields to any folder. Your custom fields can range from a simple data type, such as a text field, to a complex data type, such as a formula field that includes a formula to calculate the value of the field from other Outlook fields.

Creating Custom Fields

The easiest way to create and delete custom fields in Outlook is to use the Field Chooser. The Field Chooser allows you to see both the built-in Outlook fields and your custom fields. The easiest way to access the Field Chooser is to select a table view in your folder, such as any of the default Outlook views that begin with the word By. For example, in your calendar, you can switch your view to the By Category view. After selecting a table view, right-click on the column headings and select Field Chooser from the context menu, as shown in Figure 3-9.

To create the new field, click the New button, enter a name and data type for the field, and select the appropriate format. The following is a list of possible data types for fields in Outlook and the type of formatting these fields support:

  • Text. This field type can hold text strings or a combination of text strings and numbers, such as a mailing address. It can be up to 255 characters long.
  • Number. Use this type of field for numeric data (except numbers that represent currency) and for mathematical calculations. You can customize the format of this field with nine different formats, such as a scientific notation format (125.3E+03).
  • Percent. Store numeric data that is a percentage here. You can choose from four different formats. For example, you can set how many decimal places to show in the percentage, such as show only one decimal place (10.9%).
  • Currency. Store numeric data represented as currency here. You can format this data type to either show or hide the cents portion of the currency. For example, you can have this data type show either $5,232 or $5,232.10.
  • Yes/No. This field stores data that holds only one of two values for the following pairs of values: Yes/No, True/False, On/Off, or a checked or unchecked check box.
  • Date/Time. Store date and time data here. You can format this field with a number of standard formats, such as Monday, May 05, 1998 7:00 AM; 5/5/98 7:00 AM; May 5, 1998; or Mon 5/5/1998.
  • Duration. This field is for numeric time data represented as an amount of time elapsed. You can expose the data in this field in several formats, such as 12h or 12 hours. This field automatically calculates when the data in the field should be displayed as days, hours, or minutes. For example, if you set the format for this field as "12 hours" and you enter .25, Outlook automatically displays 15 minutes. You can also set the format so that Outlook takes into account only working hours. (By default, that means an 8-hour day, but you can customize the default.)
  • Keywords. This data type is used to hold multiple text values (which are separated by commas) and is similar to the Categories field used in Outlook. When creating custom views, keywords can be used to identify items. Examples of keyword field values are small, medium, and large.
  • Combination. This data type holds a combination of fields and literal text. You can show each field or only the first nonempty field. The fields created with this data type are read-only in Outlook. For more information on creating combination fields, see the next section, titled "Creating Combination Fields."
  • Formula. This data type holds the results of formulas you create. You can use the Microsoft Visual Basic expression service that is built into Outlook to create functions and operators for your formula. The fields created with this data type are read-only in Outlook. For more information on creating formula fields, see the section titled "Creating Formula Fields" later in this chapter.
  • Integer. This data type holds nondecimal numeric information. You can customize the format to be only numbers, such as 3,332, or to be "computer" numbers formatted as kilobytes, megabytes, and gigabytes.
  • click to view at full size.

    Figure 3-9. Select the Field Chooser from the context menu for a table view.

Creating Combination Fields

You can combine values from other fields with literal strings to create a new field, called a combination field. Combination fields are useful when you have many different types of fields and want to create a single field that combines them all. You can also use a combination field when you have multiple fields that hold conflicting data and you want to display only one of the fields in your form. Here's how you would create a combination field from two fields and a text fragment:

  1. In your Inbox, open the Field Chooser and click New.
  2. Enter a name for the field, such as My Follow-Up Field, and select Combination as the type of field.
  3. Click Edit.
  4. You have the choice to either join fields and text fragments together to create a combination field or show only the first nonempty field and ignore all the subsequent fields. Select the Joining Fields And Any Text Fragments To Each Other option.
  5. Type Need in the Formula box.
  6. Click the Field button, point to Frequently-Used Fields, and then click Follow Up Flag.
  7. Type By in the Formula box.
  8. Click the Field button, point to Frequently-Used Fields, and then click Due By.
  9. Click OK twice.
  10. Drag and drop this new field from the Field Chooser onto your Inbox column headings. You should see something similar to Figure 3-10.

Use a combination field when you want to expose a primary value for a specific field but also need the option to expose a field that holds a secondary value if the primary value is not available. If the primary value is available, you do not want to display the secondary value. For example, in our Document Library application, users can drag and drop Office documents into the public folder. Outlook can expose the properties of these office documents as fields. In the Outlook view, we want to expose the document author, but because users are not required to fill this property in when designing or saving the document, the Author property could be left blank. If the Author property is left blank, we want to use the From field in Outlook to display the name of the user who dragged and dropped the document into the folder. Follow the steps on the facing page to create the combination field that shows the first nonempty field.

click to view at full size.

Figure 3-10. Two different fields are combined to create a single combination field.

  1. Go to the Document Library folder you created, and open the Field Chooser.
  2. Click New.
  3. Type a name for the field, such as Document Author.
  4. Select Combination as the field type.
  5. Click Edit.
  6. Select the option named Showing Only The First Non-Empty Field, Ignoring Subsequent Ones.
  7. Click the Field button, point to All Document Fields, and click Author.
  8. Click the Field button, point to All Mail Fields, and click From.
  9. Click OK twice.
  10. Drag and drop your new field from the Field Chooser onto the view column headings. You should see a view similar to the one shown in Figure 3-11.
  11. click to view at full size.

    Figure 3-11. You can use combination fields to show the first nonempty value from multiple Outlook fields.

Creating Formula Fields

Formula fields allow you to use functions to calculate values from both standard and custom fields. These calculated values are stored inside of the formula field. Use formula fields when you need to calculate the value of one field based on other fields in your application. For example, you can use a formula field to calculate the total of an expense report or a person's wage based on the amount of time they worked multiplied by their hourly rate. Outlook makes creating formula fields quite easy by offering a simple interface for field selection and by displaying a list of all possible formulas and required inputs. You can use the provided Field and Function buttons to quickly select the fields and functions you want to use in your formula. Outlook will automatically parse your formula and check it for syntactical errors.

Formula fields do have some performance implications. First, Outlook has to process formula fields whenever values change in the application. The more complex you make your formulas, the longer Outlook will take to process them. Second, Outlook automatically recalculates formula fields whenever the current view changes. Third, Outlook does not allow you to sort, group, or filter views by using formula fields.

Follow these steps to create a formula field that displays the amount of time elapsed since an item was received. Figure 3-12 shows a custom formula field.

  1. In the Field Chooser, click New.
  2. Type a name for your new field, such as Days since received.
  3. Select Formula from the Type drop-down list.
  4. Click the Edit button.
  5. In the Formula box, type this:
  6.  IIF(DateDiff("d",[Received],Now())>=7, DateDiff("w",[Received],Now()) ? " week(s) ago",   DateDiff("d",[Received],Now()) ? " day(s) ago") 

  7. Click OK twice.
  8. Drag and drop the new field onto your view column headings. You should see the field automatically calculate. If the item was received within one week, the field displays the amount in days. If the item was received more than a week ago, the field displays the amount in weeks.
  9. click to view at full size.

    Figure 3-12. A custom formula field in an Outlook view.

Using Custom Fields in Filtered Replication

As you learned in Part I, Outlook and Exchange Server support synchronizing items offline. By default, Outlook synchronizes all the items from the server to your offline database. But what if you don't want to synchronize all the server items offline? Outlook offers the capability to synchronize subsets of information, called filtered replication. You select the parameters—either built-in or custom fields—that Outlook will use to filter the synchronized items. To set up filtered replication, follow these steps:

  1. Before setting filtered replication, you should add a custom property to the Account Tracking application by selecting the previously created Account Tracking folder, which is nested in the Favorites folder.
  2. In the Field Chooser, click New.
  3. Type txtAccountSalesRep in the Name box, and select Text as the type.
  4. Click OK.
  5. From the File menu, point to the Folder option, and then select Properties For Account Tracking.
  6. Click on the Synchronization tab. In the This Folder Is Available area, make sure that the When Offline Or Online option is selected.
  7. Click the Filter button.
  8. In the Filter dialog box, click on the Advanced tab.
  9. Click the Field button, point to User-Defined Fields In Folder, and click txtAccountSalesRep.
  10. From the Condition drop-down list, select Is (Exactly). In the Value text box, type the name of a user of the Account Tracking application.
  11. Click the Add To List button to add your criteria. Your screen should look like Figure 3-13.
  12. Click OK, click Yes, and then click OK twice. Now only the items meeting your criteria will be synchronized to your offline database.

Figure 3-14 shows the folder before setting filtered replication and after setting filtered replication. As you can see, a subset of the information in the folder is available to the client offline.

click to view at full size.

Figure 3-13. The Filter dialog box, showing synchronization information for the Account Tracking application.

click to view at full size.

Figure 3-14. The Account Tracking folder before filtered replication, and the Account Tracking folder after filtered replication. Notice how a subset of items are synchronized offline.



Programming Microsoft Outlook and Microsoft Exchange
Programming Microsoft Outlook and Microsoft Exchange, Second Edition (DV-MPS Programming)
ISBN: 0735610193
EAN: 2147483647
Year: 2000
Pages: 184

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