ID: Q196508
The information in this article applies to:
With Microsoft Outlook, you can create folders to hold AppointmentItems. However, if you use CDO to retrieve an AppointmentItem-type of CDO object from that folder, you only receive a Message-type of CDO object. As a result, you cannot access some AppointmentItem-specific properties such as Location, StartTime, and EndTime.
CDO only supports retrieving AppointmentItem objects from the Calendar folder of the default message store for a particular profile. Even though you can create other folders that can store AppointmentItems, you cannot retrieve an AppointmentItem (where the Class property of the object is 26) from that folder. You can only get a Message item (where the Class property of the object is 3).
As long as you are not working within the context of a service application or an Active Server Pages page, you can use the Microsoft Outlook object model to work with appointments in folders other than the Calendar folder for the default message store.
The following code retrieves an AppointmentItem from a folder named HoldAppt, which is a subfolder of Personal Folders. This code assumes that you have at least one appointment in this folder. To compile and run this code, be sure that you have added a project reference to the Microsoft Outlook 98 type library.
Private Sub Command1_Click()
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objExplorer As Outlook.Explorer
Dim colFolders As Outlook.Folders
Dim objFolder As Outlook.MAPIFolder
Dim objItem As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
objNamespace.Logon ShowDialog:=True
' Top level folders.
Set colFolders = objNamespace.Folders
Set objFolder = colFolders.Item("Personal Folders")
' Navigate down one level.
Set colFolders = objFolder.Folders
Set objFolder = colFolders.Item("HoldAppt")
' Get the first AppointmentItem.
Set objItem = objFolder.Items(1)
' You can access any of the standard AppointmentItem properties,
' such as the following:
MsgBox objItem.Subject, 0, "Subject"
MsgBox objItem.Location, 0, "Location"
MsgBox objItem.Start, 0, "StartTime"
MsgBox objItem.End, 0, "End Time"
objNamespace.Logoff
End Sub
The following code uses CDO to retrieve an AppointmentItem from a folder named HoldAppt, which is a subfolder of Personal Folders. The code assumes that you have at least one appointment stored in that folder. To compile and run this code, be sure that you have added a Project Reference to the Microsoft CDO 1.2 (or later) library.
Dim objSession As MAPI.Session
Dim fHoldAppt As Folder
Dim objAppt As AppointmentItem
' If you define the object variable as AppointmentItem, you
' will get a type mismatch error at runtime at the following line:
' Set objMsg = fHoldAppt.Messages.GetFirst
Dim objMsg As Object
Private Sub Command1_Click()
Set objSession = CreateObject("MAPI.Session")
objSession.Logon
MsgBox "Cdo Version = " & objSession.Version
Set pFolder = objSession.InfoStores("Personal Folders")
Set fRootFolder = pFolder.RootFolder
Set fHoldAppt = fRootFolder.Folders("HoldAppt")
Set objMsg = fHoldAppt.Messages.GetFirst
MsgBox "Type = " & objMsg.Type
MsgBox "Class = " & objMsg.Class
MsgBox "Subject = " & objMsg.Subject
' The following code fails to retrieve each of the following
' properties, because objMsg.Class is 3 (Message) and not 26
' (AppointmentItem). In other words, objMsg is actually a message
' object not an AppointmentItem object.
MsgBox "Location = " & objMsg.Location
MsgBox "Start Time = " & objMsg.StartTime
MsgBox "End Time = " & objMsg.EndTime
objSession.Logoff
Set objSession = Nothing
Set fHoldAppt = Nothing
Set objAppt = Nothing
Set objMsg = Nothing
End Sub
For information on how to use CDO from an Event Scripting Agent to process meeting items in Calendar folder, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q194806
TITLE : PRB: Message.Class Incorrect After Calling GetMessage()
Additional query words:
Keywords : kbcode kbCDO120 kbCDO121 kbMsg
Version : WINDOWS:1.2,1.21
Issue type : kbprb
Last Reviewed: December 2, 1998