Article ID: 196508
Article Last Modified on 3/4/2004
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
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
Keywords: kbmsg kbprb kbcode KB196508