NameSpace Events
Events that follow Application events are not available in the VBA Editor window unless you explicitly declare object variables and use the WithEvents keyword. If you look at "Using WithEvents for Child Objects" earlier in this chapter, you'll see that the NameSpace object is declared as a public variable in ThisOutlookSession using the WithEvents keyword. However, mere declaration of the variable is not sufficient. You must instantiate the NameSpace object variable in the Startup event of the Application object or use an event handler procedure to create an instance of the NameSpace object. If you don't instantiate the child object in another procedure, the event code that you write for the child object will not actually fire when the event occurs.
OptionsPagesAdd
Oddly enough, the NameSpace object supports only one event, the OptionsPagesAdd event. This event is the first cousin of the OptionsPagesAdd event for the Application object. OptionsPagesAdd for the NameSpace object occurs before a Folder Properties dialog box is displayed for a folder. The folder for which the Folder Properties dialog box is displayed is then passed as a MAPIFolder object to the event procedure for OptionsPagesAdd. You can use the OptionsPagesAdd event of the NameSpace object to add property pages to the Folder Properties dialog box for a given folder. If the folder passed to the OptionsPagesAdd event is the default Contacts folder, the following example displays the property page shown in Figure 9-9:
Private Sub objNS_OptionsPagesAdd(ByVal Pages As PropertyPages, _ ByVal Folder As MAPIFolder) Dim strCaption As String 'Only display for default Contacts folder If Folder = objNS.GetDefaultFolder(olFolderContacts) Then strCaption = Folder.Name & " Sample Page" Pages.Add "PPE.SamplePage", strCaption End If End Sub
Notice that with the Folder object passed to the procedure, you can change the caption of the property page to reflect the folder name, as shown in Figure 9-9.
Figure 9.9 - The Sample Page property page is added to the Contacts folder properties dialog box
For a complete listing of the procedures required to create an ActiveX control that serves as a container for an Outlook property page, see Chapter 14. You can also examine the source code for the Sample Page ActiveX control in the Sample Page Property Page Example folder under the Creating COM Add-Ins With Visual Basic folder in the Building Applications With Microsoft Outlook 2002 personal folders (.pst) file accompanying this book.
No comments:
Post a Comment