Outlook Viewctl Restriction Today

Cancel

□ Microsoft RernoteData Control, version G.O

□ Microsoft Rich Textbox Control, version S.A

□ Microsoft Scriptlet Component !□ Microsoft Shell Folder View Router

Selected Items Only

Microsoft Outlook View Control

Location CAPR D G RA~1 \M ICR 0 S ~3\G fficel û\D U T LCT l_ L) L L

Figure 15.4 -Add the Outlook View Control to your Control Toolbox.

To add the Outlook View Control to your form

1. Drag the View control from the Control Toolbox to your form. The default name of the Outlook View Control is ViewCtl.

2. The View control will default to showing the contents of your Inbox.

Programmatic control of the Outlook View control is straightforward. The control exposes many methods that are equivalent to Outlook menu commands. The two most important properties exposed by the View control are the Folder and View properties. These properties let you manage the current folder and view that is displayed in the control. Both the View and Folder properties are strings. While you might expect the Folder property to be a MAPIFolder object, it is a string value that indicates the full path to the target folder. You can see the Folder property in the caption of the UserForm, as shown previously in Figure 15-3. To set the Folder property for the View control when you have only a MAPIFolder object (such as the MAPIFolder object returned by thePickFolder method of the NameSpace object), use the GetFolderPath function listed in Chapter 11, "Using Visual Basic, VBA, or VBScript with Outlook," in the section, 'Returning a Folder Path from a Folder." Or you can use the FolderPath property of the MAPIFolder object to obtain a full folder path.

The GetFolderPath function returns a folder path with one leading backslash instead of two leading backslashes. The Outlook 2002 FolderPath property returns a folder path with two leading backslashes (\\). The View Control will accept either one or two leading backslashes when you set the Folder property for the control.

Outlook View Control Properties

The following table lists the properties of the Outlook View Control. Property Type Description

Active F older Object Returns an Active F older object for use when the control is hosted in a Web page.

DeferUpdate Boolean Causes updates to the control to be deferred until ttt&rceUpdate method is called.

Filter String Applies a DAV Searching and Locating (DASL) query to the view currently displayed in the control. Use this property with caution.

FilterAppend String Applies a logical AND of thBilterAppend string to the Filter property. Use this property with caution.

Folder String Returns or sets the path of the folder displayed by the control.

ItemCount Long Returns the number of items in the folder displayed in the control.

NameSpace String Returns or sets the NameSpace property of the control. This property always returns MAPI.

OutlookAppIication Object Returns an Outlook Application object for use when the control is hosted in a folder home page.

Restriction String Applies a filter to the items displayed in the control, displaying only those items that contain the string in the filter. Note that the behavior of the control's Restriction property differs from the Restrict method in the Outlook Object Model. See Restrict in the Microsoft Outlook Help Reference for additional details on logical and comparison operators.

Selection Object Returns a Selection collection object for the items that are currently selected in the control.

View String Returns or sets the name of the view in the control. Setting this property to a value that does not match a view name listed above does not cause the view to change, although this property will subsequently return the invalid view name.

ViewXML String Returns or sets the XML for the view displayed in the control.

Outlook View Control Methods

The following table lists the methods of the Outlook View Control.

Method Description

AddressBook

Displays the Outlook Address Book dialog box.

AddToPFFa vorites

Adds the folder displayed in the control to the user's Favorites folder. Does not display the Add To Favorites dialog box.

AdvancedFind

Displays the Outlook Advanced Find dialog box.

Categories

Displays the Outlook Categories dialog box for the item or items currently selected in the control, allowing the user to select categories for the current item or to modify the master category list.

CollapseAIIGroups

Collapses all displayed groups in the control. If the view displayed in the control does not group items, this method has no effect.

CollapseGroup

Collapses the currently selected group in the control. If the view displayed in the control does not group items or if an item in the view is selected, this method has no effect.

Customize View Delete

Displays the Outlook View Summary dialog box, allowing the user to customize the current view in the control.

Deletes the currently selected groups or items in the control. If one or more groups are selected, the groups and all items in the groups will be deleted.

ExpandAIIGroups

Expands all displayed groups in the control. If the view displayed in the control does not group items, this method has no effect.

ExpandGroup

Expands the currently selected group in the control. If the view displayed in the control does not group items or if an item in the view is selected, this method has no effect.

Flag! tern

Displays the Outlook Flag For Follow Up dialog box for the selected item.

ForceUpdate

Refreshes the view in the control.

Forward

Executes the Forward action for the selected item or items in the control.

GoToDate (newDafe as String)

Sets the displayed date in the control to the date specified/to^wDafe. This method affects only views of the Calendar folder.

GoToToday

Sets the displayed day in the control to the current day. This method affects only views of Calendar folder and Timeline views in the Inbox and Task folders.

GroupBy

Displays the Outlook Group By dialog box, allowing the user to group items in the current view. This method has no effect if the current view does not display grouped items.

MarkAIIAsRead

Marks all items as read in the folder displayed in the control. The user is prompted for confirmation before any change is made.

MarkAsRead

Marks all selected items as read in the control. The user is prompted for confirmation before any change is made.

MarkAsUnread

Marks all selected items as unread in the control. The user is prompted for confirmation before any change is made.

Move! tern

Displays the Outlook Move Items dialog box for the items selected in the control.

NewAppointmen t

Creates and displays a new appointment.

NewContact NewDefaultltem

Creates and displays a new contact. If the control is displaying a Contacts folder, when the new contact is saved, it is saved in the folder displayed in the control. Otherwise, the contact is saved in the user's default Contacts folder.

Creates and displays a new Outlook item. The item type is the default item type for the folder displayed in the control.

NewForm

Displays the Outlook Choose Form dialog box, allowing a user to create a new Outlook item by selecting a form from a forms library.

NewJournalEntry

Creates and displays a new Journal entry. If the control is displaying a Journal folder, when the new journal entry is saved, it is saved in the folder displayed in the control. Otherwise, the journal entry is saved in the user's default Journal folder.

NewMeetingRequest

Creates and displays a new meeting request. If the control is displaying a Calendar folder, when the meeting request is sent, the corresponding appointment is saved in the folder displayed in the control. Otherwise, the appointment is saved in the user's default Calendar folder. Responses to the meeting request are tallied only if the appointment is saved in the user's default Calendar folder.

NewMessage

Creates and displays a new e-mail message.

NewOfficeDocument

Displays the Outlook New Office Document dialog box. This method prompts the user to select the type of Office document to create and then launches the appropriate Office application.

NewPost

Creates and displays a new post item. When the user posts the message, it is posted to the folder displayed in the control. This method has no effect if the folder displayed in the control does not support messages.

NewTask

Creates and displays a new task. If the control is displaying a Tasks folder, when the new task is saved, it is saved in the folder displayed in the control. Otherwise, the task is saved in the user's default Tasks folder.

New TaskRequest

Creates and displays a new task request.

Open

Opens the item or items currently selected in the control.

OpenSharedDefa ultFolder

Displays a specified user's default folder in the control. This method takes two arguments. These arguments are the same as the arguments Id&tM&haredDefaultFolder method of the Namespace object in the Outlook object model. An error occurs if the user running the control does not have permission to access the specified folder.

Print! tern

Prints the currently selected items in the control. If a group is selected, the items in the group are selected and printed. The Print dialog box is displayed to allow the user to specify how the items are to be printed.

Reply

Executes the Reply action for the selected item or items in the contrSJep/yA//Executes the ReplyAII action for the selected item or items in the control.

ReplylnFolder

Creates a Post item for each currently selected message in the control. The Post item contains the text of the message it is replying to and has the same conversation topic.

SaveAs

SendAndReceive

Saves the selected items in the control as a file. The Save As dialog box is displayed to allow the user to select the location and format of the resulting file. If more than one item is selected, the items are concatenated and saved as a text file; otherwise, the user is allowed to choose from several file formats.

Sends messages in the Outbox folder and checks for new messages.

ShowFields

Displays the Outlook Show Fields dialog box, allowing the user to select the fields to be displayed in the current view in the control.

Method Description

Sort Displays the Outlook Sort dialog box, allowing the user to sort the contents of the control using multiple criteria.

SynchFolder Synchronizes the displayed folder In the control for off-line use.

Outlook View Control Events

Event support Is a new feature of the Outlook 2002 View Control. The Outlook 2002 View Control events make It possible to perform some helpful tasks that you couldn't do with the Outlook 2000 View Control. For example, you can now easily trap the SelectlonChange event, which fires for the folder displayed in the control and is Independent of the CurrentFolder property In the Outlook ActlveExplorer object. If no ActlveExplorer object exists in Outlook, the SelectlonChange event still fires. With the Outlook 2000 View Control, the only way to trap a SelectionChange event was to ensure that the CurrentFolder property for the ActiveExplorer object was the same as the folder for the View Control. The Outlook 2002 View Control has done away with this requirement; Instead, it fires the SelectlonChange event whenever the selection changes In the view. The following table lists the events for the Outlook 2002 View Control.

Event

Activate

BeforeVlewSwitch ( newView as String, Cancel as Yes Boolean)

SelectlonChange

Cancelable Description

No Occurs when the View Control becomes the active element on the page, either as the result of user action or through program code.

Occurs before the View Control changes to a new view, either as the result of user action or through program code.

Occurs when the selection of the current view changes. Use the Selection property of the View Control to obtain a Selection collection object that contains selected Items.

Occurs when the view In the View Control changes, either as the result of user action or through program code.

Obtaining Views for the Active Folder

One Important piece of code behind the Outlook View Control User Form Is the GetFolderViews procedure. GetFolderViews returns a variant array that contains the views available In the folder displayed In the control. When a user clicks the Pick Folder button, she or he can select a different folder in the folders available to the current logged-on Outlook user. ThecmdPickFolder_Click procedure lets the user select a different folder for display In the Outlook View Control. This procedure calls the GetFolderViews procedure that Iterates the views In the folder by using the new Views collection object. Here's the code:

Private Sub cmdPickFolder_Click() On Error Resume Next Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.PickFolder If objFolder Is Nothing Then

Exit Sub 'If user pressed cancel End If

'Prevents cmbView_Change event from firing blnViewChange = True cmbView.Clear

OVCtM .Folder = objFolder.FolderPath

Me.Caption = objFolder.FolderPath

'Get views in the new folder cmbView.List = GetFolderViews(objFolder)

If cmbView.List(0) = "" Then 'Handles error condition cmbView.Value ="" Else cmbView.Value = OVCtH .View If Err = 380 Then 'Invalid property assignment 'View Control active view name is incorrect cmbView.Value = cmbView.List(0) OVCtM .View = cmbView.List(0) End If End If

'Done - allow cmbView_Change to fire blnViewChange = False End Sub

Function GetFolderViews(objFolder As MAPI Folder) As Variant On Error Resume Next Dim avarArray Dim i As Integer

ReDim avarArray(objFolder.Views.Count -1) For i = 1 To objFolder.Views.Count avarArray(i -1) = objFolder.Views(i).Name Next

GetFolderViews = avarArray End Function

Using the View Control in an HTML Page

One special feature of the Outlook View Control Is that you can use It on an HTML page as well as on the page of an Outlook form. The control can be used In any of the environments listed In the table below. When the control Is running purely within Internet Explorer, Its scrlptablllty Is limited for security reasons. When you host the control within an HTML page with Internet Explorer as the container application, you will not be able to access the full Outlook Object Model programmatlcally. Access to the Outlook 2002 Object Model Is also limited by the restrictions of the Outlook 2002 E-Mail Security Update.

Environment

HTML Page In Internet Explorer 4c.or later running outside Outlook Web View

HTML Page In Outlook folder home page

Outlook Custom Form

Office UserForm

Visual Basic Form

Outlook 2002 Object Model Exposed

No Yes Yes Yes Yes

Accessing the Outlook Application Object

Remember that you can access the Outlook Application object only when your Web page is hosted In Outlook. You can use either the OutlookAppllcation property of the Outlook View Control or Window.External.OutlookAppllcation to obtain an Instance of an Outlook Application object. Once you have access to the Outlook Application object, you can Instantiate all the child objects of the Outlook Object Model In DHTML code, subject to the limitations of the Outlook E-Mail Security Update. If the Web page is displayed as a folder home page within Outlook, the following code In thewindow_onload procedure creates an Outlook Application object named g_App.

This discussion assumes that you have a basic understanding of Hypertext Markup Language (HTML), Dynamic HTML (DHTML), and Cascading Style Sheets (CSS). For additional Information on HTML, DHTML, and CSS, visit http://msdn.microsoft.com/workshop/author.

<script language="VBScript"> 'Script-level variables dim g_App, g_TheExplorer, g_CommandBars, g_NameSpace

Sub Window_onload()

On Error Resume Next

Set g_App = ViewCtH .OutlookApplication

Set g_TheExplorer = g_App.ActiveExplorer

Set g_CommandBars = g_TheExplorer.CommandBars

Set g_NameSpace = ViewCtM .OutlookApplication.GetNamespace("MAPI")

'Alternative code

'Set g_App = window.external.OutlookApplication

End Sub

Using FrontPage 2002 with the Outlook View Control

When you design a Web page with the Outlook 2002 View Control, you can use any of the design tools listed to Insert the View Control into your Web page. For example, in FrontPage 2002, you can use the following steps to Insert the View Control into your Web page.

To Insert the Outlook View Control Into a Web page using FrontPage 2002

1. On the File menu, point to New, and then click Page Or Web.

2. In theNew Page OrWebtask pane, under New, click Blank Page.

3. On the Insert menu, select Insert Web Component.

4. In the Component Type list box, scroll to the bottom of the list and select Advanced Controls.

5. In the Choose A Control list box, select ActiveX Control.

6. Click Next.

7. Click the Customize button.

8. In the Customize ActiveX Control List dialog box, scroll down In the Control list box and check Microsoft Outlook View Control. Then click OK.

9. Select Microsoft Outlook View Control in the Choose A Control list box, and click Finish.

Don't worry if you can't see the contents of the Outlook View Control in the Normal or Preview panes. The control might be grayed out, as shown in Figure 15-5. You can see the operational View Control when you click the Preview In Browser button on the FrontPage toolbar to display your Web page in a browser.

Figure 15.5 - The Outlook View Control on a Web page in FrontPage 2002.

The Outlook View Control has now been inserted in your Web page, as shown in Figure 15-5. To continue using the FrontPage interface, right-click the View Control in the Normal pane. Then set properties for the control, such as the Height, Width, View, and Folder properties in the ActiveX Control Properties dialog box (shown in Figure 15-6).

Figure 15.6 - Use the ActiveX Control Properties dialog box to set properties for the Outlook View Control.

To set properties for the Outlook View Control

1. Right-click the Outlook View Control in the Normal pane.

2. Select ActiveX Control Properties from the shortcut menu.

3. Set properties such as Height, Width, and Border on the Object Tag page.

4. Click the Parameters tab to modify unique Outlook View Control properties.

5. Select the property to modify in the Additional Parameters list box.

6. Click the Modify button and enter a value such as Inbox For Folder or Messages For View in the Data edit box. Use a full folder path for folders that are not default Mailbox folders, such as WPublic Folders\AII Public Folders\Northwind Contact Management Applications\ Companies. If you enter an invalid value for the Folder or View property, the Outlook View Control will not display data when you preview the page in a browser.

One problem with setting properties for the Outlook View Control with FrontPage 2002 is that FrontPage sometimes sets extraneous parameters. For example, the ViewXML parameter of the control can sometimes contain the XML for the view in the Value property in the control's HTML markup. You should delete any Value property in theViewXML parameter, unless you explicitly want to use this parameter to create a custom view in the Outlook View Control.

HTML Markup for the Outlook View Control

Experienced Web designers will find it more productive to insert HTML markup for the Outlook 2002 View Control directly into the HTML for the Web page. Unlike the markup for the Outlook 2000 View Control, you do not have to add a Code base tag to download the control in case it isn't installed on a user's machine. Because the Outlook View Control is an integral component of Outlook 2002, a Web download is not required. Here is the basic HTML markup for the Outlook View Control:

<object classid="clsid:0006F063-0000-0000-C000-000000000046" id="ViewCtl1 ">

<param

name:

-'View" value=>

<param

name:

-'Folder" value=>

<param

name:

-'Namespace" value="MAPI">

<param

name:

-'Restriction" value>

<param

name:

="DeferUpdate" value="0">

<param

name:

-'Dirty" value="0">

<param

name:

-'Filter" value>

<param

name:

-'FilterAppend" value>

<param

name:

-'EnableRowPersistance" value="0">

<param

name:

="ViewXML" value=>

</object>

Was this article helpful?

0 0

Post a comment