Manipulating the User Interface: The Inspector Object

[Previous] [Next]

The Pages collection is returned to you by the ModifiedFormPages property on the Outlook Inspector object. Through the Pages collection, you can access the individual form pages, which are the tabs at the top of your Outlook form, either by using their names or by using indexes. Also, by using the methods of the Pages collection object, you can create dynamic applications for your users by adding new or hiding form pages based on the users' selections. The following code snippet shows you how you can display the name of all the pages in the Pages collection object:

     Sub CommandButton1_Click         set oPages = Item.GetInspector.ModifiedFormPages         msgbox "There are " & oPages.Count & " custom pages on your form."         for i = 1 to oPages.Count             msgbox "Page #" & i & " is called " & oPages.Item(i).Name         next     End Sub 

Pages Collection Properties

The only property you will probably use in your applications for the Pages collection is the Count property. The Count property returns the number of objects contained in the collection. As you can see from the preceding code snippet, the Count property can be used to scroll through the Pages collection to print out or find the correct form page needed by your application.

Pages Collection Methods

The Pages collection exposes a number of methods that allow you to add, remove, or access a specific form page in your application. This access in turn allows you to develop solutions that dynamically change as your customers use them. For example, using the methods of the Pages collection, you could build an application that dynamically exposes new pages based on your users' input. The following section describes the different methods for the Pages collection.

Add Method

The Pages collection implements an Add method so that you can quickly add new form pages to your application programmatically. While this provides you great flexibility in developing custom user interfaces for your application, you have to remember that you can have only as many as five custom pages in an Outlook application. If you try to add a sixth page in Outlook, you will receive an error message. If you hit this five-page limit and need to add more user-interface elements that implements tab in your application at run time, you should programmatically create a multitab control on your Outlook form by using the Controls collection. (The Controls collection is discussed later in this supplement.) The following code shows you to use the Add method:

     Sub CommandButton1_Click         set oPages = Item.GetInspector.ModifiedFormPages         set oNewPage = oPages.Add("My New Page")     End Sub 

Remove Method

Outlook allows you to remove pages from the collection. To remove pages, you must pass in the index of the item to be removed to the Remove method; you cannot pass the name of the form page. (You could write a function that uses the Count property and a While loop to find out the index of the form page for you.) The following code snippet shows you how to remove an item based on its index:

     Sub CommandButton1_Click         Set oPages = Item.GetInspector.ModifiedFormPages         oPages.Remove(1)     End Sub 

Item Method

To access a specific page in an Outlook form, you can use the Item method of the Pages collection. The Item method can take either the index of the item in the collection or the name of the item. The following example shows you how to access a custom page named P.2 in a message form by using three different methods:

       Sub CommandButton1_Click         set oPages = Item.GetInspector.ModifiedFormPages         set oP2 = oPages("P.2")         set oP2other = oPages.Item(1)         set oP2yetanother = oPages.Item("P.2")         msgbox oP2.ActiveControl.Name         msgbox oP2other.ActiveControl.Name         msgbox oP2yetanother.ActiveControl.Name     End Sub 



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