Outlook View Control

Outlook View Control

he Outlook View control released by Microsoft allows you to display an Outlook folder in your application. The folder displayed in the control is fully functional; you can create, open, and delete items. In addition, you can right-click on an item and choose a command from the pop-up menu. With a little creativity, this capability enables you to incorporate powerful features into your application. For example, suppose you are writing an application for an organization in which a manager must be able to view and modify employee schedules. The ideal interface for this application is a calendar with a list of employees next to it, from which the manager can select an employee and view the selected employee’s schedule in the calendar.

The Outlook View control requires Outlook 2000 to be installed on the machine running the control. You can check if you have the control (outlctlx.dll) by bringing up VB’s Component dialog box; it is listed as outlctlx Type Library. If you don’t have it, it’s is part of the Team Folder Wizard Kit which you can download from Microsoft.

The table lists the primary properties and methods of the Outlook View control.

Folder property Designates which folder to display. Top level folders are prefixed with \ ; for example, \Personal FoldersCalendar
View property Sets the View of the folder. Although you can set a Calendar to the Day/Week/Month view, there doesn’t seem to be a way to set it to specifically Day, Week, or Month, as you can on Outlook’s View menu.
Restriction property Filters which items are displayed in the folder based on filter string.
OpenSharedDefaultFolder method Open another user’s folder.
NewMessage method
Creates and displays a new item.

Unfortunately, the control does not implement events that would allow you to respond to a user’s actions. One word of warning: the design time behavior of the control is not perfected yet. Setting some of the properties in the Properties window such as the Folder property raises an error; you have to set them in code. Another issue is that the control is live during design time, so clicking on it activates it rather than selects it. To select it, choose it in the Properties window.

Let’s develop a sample app using the example of the manager viewing and modifying employee schedules. This sample app assumes that you are part of an organization with several users that have granted you sharing permission to their calendars. Add the Outlook View control to the Toolbox and drag it on to a form. If you aren’t logged on to Outlook, it will attempt to log on. By default it displays your Inbox. Name the control ovCalendar. Add a Listbox to the form with a list of the people in your organization. In the Change Event of the Listbox, we’ll open the selected user’s calendar using the OpenSharedDefaultFolder method, which takes two arguments: the user name and folder type. For the user name, you can pass any name that Outlook can resolve. If it doesn’t recognize the name or there is more than one match, then a runtime error will be raised. Here’s the code for the ListBox’s Change Event:

ovCalendar.OpenSharedDefaultFolder lst.List(lst.ListIndex), olFolderCalendar

An alternative approach is to use one calendar for all appointments and filter which appointments are displayed based on the selected employee. This can be done using the Restriction property, which takes a filter criterion as a string. The syntax for the filter is a field name enclosed in brackets followed by an operator and the criteria. You can join multiple clauses with And and Or operators. For our sample app, we must put the employee’s name in a field in the folder so that we can apply a filter to the folder based on the employee’s name. We can either add a custom field to the folder or put the name in an existing field. To keep things simple, we’ll put the employee’s name in the Subject field. Unfortunately, the Restriction property doesn’t seem to work when the Calendar is in Day/Week/Month/View, so set the Calendar to a Table type view. (If you don’t have a Table type View on the View menu in Outlook, you can create one by choosing Define Views from the ViewCurrent View menu.) You can change the View in code by setting the control’s View, or you can set the View in Outlook and the control will default to the current View. However, you must move off the folder for Outlook to record the new View as the current View. The code for the ListBox’s Change event is:

ovCalendar.Restriction = "[subject]='" & lst.List(lst.ListIndex) & "'"

The Outlook View control is obviously a first release, but it has a lot of potential. I hope for a future release that implements events that allow you to respond to user actions such as when a user selects an item. It would also be helpful to have a property that allows you to determine which item is selected in the folder. I also hope they restrict property to work with all Views.


Share the Post: