Handling Message Items

The Message object provides methods for copying, moving, and deleting messages. An automated email client may need to move incoming helpdesk inquiries, for example, to an appropriate folder for later retrieval by the next available technician.

To move an email message from one folder to another, use the Message object’s MoveTo method. Its syntax is:

Set CdoMessage2 = CdoMessage.MoveTo(FolderID[, StoreID])

The parameters are:


A string that identifies the folder to which the message is to be moved. A folder ID string is obtained from the ID property of a CDO Folder object. Obtaining CDO Folder objects representing specific folders is the subject of the next section.


This optional parameter is a string that identifies the message store containing the target folder. If omitted, CDO assumes that the target folder resides in the same message store as the folder from which the message is being moved. A message store ID is obtained from the ID property of a CDO InfoStore object.

The CDO Message object returned by the MoveTo method (shown as CdoMessage2 in the syntax definition) references the message in its new location. The original CDO Message object (shown as CdoMessage) no longer references any message. Attempting to access its properties results in an error.

Here’s an example of using the MoveTo method:

' CdoMessage and CdoFolder previously Dim'ed and Set.
Set CdoMessage = CdoMessage.MoveTo(CdoFolder.ID, CdoFolder.StoreID)

Note the following in ...

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.