PRB: Can't Attach Appointment As An Embedded Item Into A Message

ID: Q240033


The information in this article applies to:
  • Collaboration Data Objects (CDO), versions 1.2, 1.21


SYMPTOMS

Trying to add an appointment item as an attachment to a message results in the following error message:

MAPI_E_UNKNOWN_ENTRYID(80040201)
You get this error message when you set the Source method of the message object.


CAUSE

CDO does not support attaching appointments into messages.


RESOLUTION

You can use Outlook Object Model to attach attachments into messages. The following sample code assumes that you have a reference to Microsoft Outlook Object Library. The name of the library is "Microsoft Outlook 9.0 Object Library" for Microsoft Outlook 2000. To run the code, you should also have at least one appointment item in your default Calendar folder.


Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
objNamespace.Logon ShowDialog:=True

'Get to the default Calendar folder
Set objFolder = objNamespace.GetDefaultFolder(olFolderCalendar)
 
'Get the first AppointmentItem in the Calendar folder.
Set oAppt = objFolder.Items(1)
 
'Create a message
Set myItem = objOutlook.CreateItem(olMailItem)
myItem.Subject = "Attach AppointmentItem"
Set myRecipient = myItem.Recipients.Add("Recipient Name") 'TO DO: Add a valid recipient name here.
myRecipient.Resolve
 
'Attach the AppointmentItem into the message
Set myAttachments = myItem.Attachments
myAttachments.Add oAppt, 5, 1
  
myItem.Send

objNamespace.Logoff 


STATUS

This behavior is by design.


MORE INFORMATION

The following Microsoft Visual Basic code can be used to reproduce the behavior with CDO library. The sample code assumes that you have a reference to Microsoft Collaboration Data Objects library within your Microsoft Visual Basic project. To run the code, you should also have at least one appointment item in your default Calendar folder.


Set oSess = CreateObject("MAPI.Session")
oSess.Logon
 
'Get to the default Calendar folder
Set oFolder = oSess.GetDefaultFolder(0)
Set oMess = oFolder.Messages

'Get the first AppointmentItem in the Calendar folder.
Set oAppt = oMess(1)

'Create a message
Set objmsgs = oSess.Inbox.Messages
Set objMsg = objmsgs.Add
Set orecip = objMsg.Recipients.Add
orecip.Name = "Recipient Name" 'TO DO: Please put a valid recipient name here
orecip.Resolve

objMsg.Subject = "Test Message"
objMsg.Text = "This is the body of the message."

'Attach the AppointmentItem into the message
Set objAttach = objMsg.Attachments.Add
objAttach.Position = 0
objAttach.Type = CdoEmbeddedMessage 
objAttach.Source = oAppt.ID 'You will get MAPI_E_UNKNOWN_ENTRYID(80040201) error message
objMsg.Send
oSess.Logoff
 

Additional query words: appointment, attachment, outlook

Keywords : kbCDO kbCDO120 kbCDO121 kbMsg kbVBp kbGrpMsg kbDSupport
Version : WINDOWS:1.2,1.21
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: October 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.