OL2000: Cannot Programmatically Create or Modify Views

Article translations Article translations
Article ID: 262294 - View products that this article applies to.
This article was previously published under Q262294
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

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 "total Hidden messages = " & iNumMessages
   For i = 1 To iNumMessages
      If cHiddenMsgs(i).Type = "IPM.Microsoft.FolderDesign.NamedView" 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

REFERENCES

For additional information about available resources and answersto commonly asked questions about Microsoft Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:
146636 OL2000: Questions About Custom Forms and Outlook Solutions

Properties

Article ID: 262294 - Last Review: October 20, 2013 - Revision: 3.0
APPLIES TO
  • Microsoft Outlook 2000 Standard Edition
Keywords: 
kbnosurvey kbarchive kbhowto KB262294