Common Methods and Properties for All Outlook Items

[Previous] [Next]

The UserProperties collection represents the custom properties for the Outlook item. Figure C-7 shows the Account Tracking form with some of its custom properties. You can use the methods and properties of this collection to quickly count, find, or add new properties to your application programmatically.

click to view at full size.

Figure C-7 Custom properties on the Account Tracking form.

UserProperties Collection Methods

The following section describes the methods of this collection in more detail. The properties are not discussed because the most frequently used property is Count, which we examined earlier when we looked at other collections.

Add Method

The Add method creates a new custom property and returns it as a new UserProperty object. This method takes two required parameters and two optional parameters. The required parameters are the name of the property and the type of property. The type can be one of the following constants: olCombination (19), olCurrency (14), olDateTime (5), olDuration (7), olFormula (18), olKeywords (11), olNumber (3), olPercent (12), olText (1), or olYesNo (6). The optional parameters indicate whether or not the new property should be added to folder fields and what display format to use for the property. The display format constants depend on the type of new property. To figure out which display format constants you can use, in your custom form, click the New button in the Field Chooser. Select the type of user property you want to create. The Format drop-down list box contains all the formats for those fields; the first format in the drop-down box corresponds to an index of 1. For example, if you select Percent as your user property type, the display format constant of 4 would correspond to All Digits.

The following code sample dynamically adds a text box named TextBox1 to an item in your Inbox, creates a new user property, adds a value to the new user property of the Formula type, specifies the formula text to use for the user property, and displays the results in the text box:

     Sub CommandButton1_Click         set oNS = Application.GetNameSpace("MAPI")         set oItem = oNS.GetDefaultFolder(6).Items.GetFirst         set oNewProp = oItem.UserProperties.Add("NewFormula",18)         oNewProp.Formula = """The current message is in the "" & _             [In Folder] & "" folder."""         set oFormPage = oItem.GetInspector.ModifiedFormPages.Add( _             "New Page")         set oNewControl = oFormPage.Controls.Add("Forms.TextBox.1")         oNewControl.AutoSize = True         oNewControl.Value = oNewProp.Value         oItem.Display     End Sub 

Find Method

The Find method allows you to quickly find a UserProperty object in the collection that corresponds to your specific filter. The following code sample shows you how to use the Find method to find a UserProperty object:

     Sub CommandButton1_Click         txtValue = Item.UserProperties.Find("MyCustomProperty").Value     End Sub 

UserProperty Object

The UserProperty object represents a custom property on an Outlook form. By using the methods and properties of this object, you can manipulate the customer properties you create in your Outlook applications. For more information about how to use the properties and methods of this object, refer to the Olform.hlp file on the companion CD.



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