O'Reilly logo

CDO & MAPI Programming with Visual Basic: by Dave Grundgeiger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

FolderID

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.

StoreID

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required