PRB: Can't Attach Appointment as an Embedded Item into a Message (240033)



The information in this article applies to:

  • Collaboration Data Objects (CDO) 1.2
  • Collaboration Data Objects (CDO) 1.21

This article was previously published under Q240033

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 (1.x) 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 (1.2, 1.21) 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

				

Modification Type:MinorLast Reviewed:3/4/2004
Keywords:kbMsg kbprb KB240033