Microsoft KB Archive/262294

= OL2000: Cannot Programmatically Create or Modify Views =

Article ID: 262294

Article Last Modified on 10/9/2003

-

APPLIES TO


 * Microsoft Outlook 2000 Standard Edition

-



This article was previously published under Q262294



SUMMARY
The Microsoft Outlook object model does not provide support for creating or modifying views. This article summarizes possible approaches that you can take to work around this limitation.



MORE INFORMATION
You may be able to use the following options to meet the needs of your solution.

Use Pre-Defined Views
The Outlook object model does allow you to change views by using the CurrentView method. Therefore, depending on how your solution is designed, you may be able to create pre-defined views in the folder and then programmatically switch views based on some criteria.

Deploy an Entire Folder
For folder-based solutions, instead of trying to dynamically create views, you should consider deploying an entire folder instead. This deploys all the views that are contained in the folder. To do this:
 * 1) Store the folder template that contains the views in a Personal Folders file (.pst).
 * 2) Use the AddStore method to programmatically add the Personal Folders file to the user's profile.
 * 3) Implement the CopyTo method to copy the folder to the location that you want.
 * 4) Use the RemoveStore method to programmatically remove the Personal Folders file from the profile.

Use the CDO Object Model to Move Views
The Collaborative Data Objects (CDO) 1.21 object model is based on the Messaging Application Programming Interface (MAPI) and generally provides lower-level access to Outlook data. CDO does not provide direct support for views, but because views are hidden messages in a folder, you can use CDO to move the messages. However, while Microsoft Product Support Services (PSS) can support moving hidden messages, PSS does not support the end result of moving views. There is no documentation about other properties or settings that you may need to change to get views that you deploy to fully function.

The following Outlook Visual Basic for Applications code illustrates how you can use CDO to access the views in your Inbox. It displays a list of the views in the Immediate window of the Visual Basic Editor. Make sure that you reference the Microsoft CDO 1.21 Library object library.

NOTE: This example only returns those views that are stored directly in your Inbox. When a view is created, you can choose to make the view available to all folders so that the view is not stored in your Inbox. Sub ShowFolderViews

Dim oSession As MAPI.Session Dim myFolderEntryID As String Dim myCDOFolder As Folder Dim myHiddenMessages As Messages Dim i As Integer, j As Integer

Set oCDOSession = New MAPI.Session oCDOSession.Logon, , False, False myFolderEntryID = Session.GetDefaultFolder(olFolderInbox).EntryID Set myCDOFolder = oCDOSession.Inbox.Parent.GetFolder(myFolderEntryID) Set cHiddenMsgs = myCDOFolder.HiddenMessages iNumMessages = cHiddenMsgs.Count Debug.Print &quot;total Hidden messages = &quot; & iNumMessages For i = 1 To iNumMessages If cHiddenMsgs(i).Type = &quot;IPM.Microsoft.FolderDesign.NamedView&quot; Then Debug.Print cHiddenMsgs(i).Subject End If  Next i End Sub For additional information about how to move messages using the CDO object model, view the following CDO documentation on MSDN Web site:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_active_messaging_legal.asp?frame=true

Create Exchange Views
As a last resort, if you must dynamically create or modify views, you must use the Exchange SDK documentation to create the older Exchange views. Outlook currently supports this older view architecture for backwards compatibility but may not support this architecture in the future. Therefore, Microsoft does not recommend that you take this approach when you design a solution for Outlook. You must be familiar with the C/C++ programming language to implement this type of solution.

For additional information about how to work with Exchange views, please view the following MSDN Web site:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/exchcli/html/_mapi1book_microsoft_exchange_client_view_descriptor_data_format.asp?frame=true

