Platform SDK: CDO 1.2.1

Add Method (Attachments Collection)

The Add method creates and returns a new Attachment object in the Attachments collection.

Syntax

Set objAttachment = objAttachColl.Add( [ name] [, position] [, type] [, source ] )

objAttachment
On successful return, contains the new Attachment object.
objAttachColl
Required. The Attachments collection object.
name
Optional. String. The display name of the attachment. The default value is an empty string. To allow a user to click on the attachment that appears in the message and activate an associated application, supply the full file name, including the file extension.
position
Optional. Long. The position of the attachment within the body text of the message. The default value is zero.
type
Optional. Long. The type of attachment; either CdoFileData, CdoFileLink, CdoOLE, or CdoEmbeddedMessage. The default value is CdoFileData.
source
Optional. String. The path and file name of the file containing the data for the attachment, or the unique identifier of the message to be embedded. The path and file name must be in the appropriate format for the attachment type, specified by the type parameter. The default value is an empty string.

Remarks

The Add method parameters correspond to the Name, Position, Type, and Source properties of the Attachment object. The source parameter is also closely related to the ReadFromFile method's fileName parameter.

You can supply the data for the attachment at the same time that you add the attachment to the collection. The Add method operates differently, depending on the value of the type parameter. The following table describes its operation.

Value of type parameter Value of source parameter
CdoFileData Specifies a full path and file name that contains the data for the attachment, for example C:\DOCUMENT\BUDGET.XLS. The data is read into the attachment.
CdoFileLink Specifies a full path and file name in a universal naming convention (UNC) format, such as \\SALES\INFO\PRODUCTS\NEWS.DOC. The attachment is a link, so the Add method does not read the data.
CdoOLE Specifies a full path and file name to a valid OLE docfile, for example C:\DOCUMENT\BUDGET2.XLS. The data is read into the attachment.
CdoEmbeddedMessage Specifies the ID property of the message to be embedded. The message is copied into the attachment.

When the type parameter has the value CdoFileLink, the source parameter is a full path and file name in a UNC format. This is suitable for sending attachments to recipients who have access to a common file server. Note that when you use the type CdoFileLink, CDO does not validate the file name.

If you do not specify the name, type, and source parameters when you call the Add method, you must later explicitly set these properties. In this case you must set Type before you set Source. Failure to do this can result in a return of CdoE_NOT_FOUND from the ReadFromFile or WriteToFile method. If the type is CdoOLE, you must also call ReadFromFile on the new Attachment object to load the attachment's content.

If you do not set the Name, Type, and Source properties on an attachment, some calendaring clients may not successfully display the AppointmentItem, MeetingItem, or Message object. Microsoft® Outlook™, for example, returns an error message when an attachment is empty, that is, has no properties set.

The Index property of the new Attachment object equals the new Count property of the Attachments collection.

Note  Microsoft Outlook supports attachments on AppointmentItem objects, but Microsoft® Schedule+ does not. For consistency of interface, the Add method always accepts a new attachment on an appointment, but if the appointment is associated with Schedule+, the attachment is ignored and discarded when you commit the appointment to storage with Send or Update.

The attachment is saved in the MAPI system when you Update or Send the parent Message object.