Platform SDK: CDO 1.2.1

Index Property (Attachment Object)

The Index property returns the index number for the Attachment object within the Attachments collection. Read-only.

Syntax

objAttachment.Index

Data Type

Long

Remarks

The Index property indicates this attachment's position within the parent Attachments collection. It can be saved and used later with the collection's Item property to reselect the same attachment in the collection.

The first object in the collection has an Index value of 1.

An index value should not be considered a static value that remains constant for the duration of a session. It can be affected when other attachments are added and deleted. The index value is changed following an update to the Message object to which the Attachments collection belongs.

The Index property does not correspond to a MAPI property and cannot be rendered into HTML hypertext by the CDO Rendering Library.

Example

Function Attachments_GetByIndex() 
Dim lIndex As Long 
Dim objOneAttach As Attachment ' assume valid attachment 
' set error handler here 
If objAttachColl Is Nothing Then 
    MsgBox "Must select an Attachments collection" 
    Exit Function 
End If 
If 0 = objAttachColl.Count Then 
    MsgBox "Must select collection with 1 or more attachments" 
    Exit Function 
End If 
' prompt user for index; for now, use 1 
Set objOneAttach = objAttachColl.Item(1) 
MsgBox "Selected attachment 1: " & objOneAttach.Name 
lIndex = objOneAttach.Index  ' save index to retrieve it later 
' 
' ... get same attachment object later 
Set objOneAttach = objAttachColl.Item(lIndex) 
If objOneAttach Is Nothing Then 
    MsgBox "Error: could not reselect the attachment" 
Else 
    MsgBox "Reselected attachment " & lIndex & _ 
            " using index: " & objOneAttach.Name 
End If 
Exit Function