Re-opening message after MessageClass changed, part 2

  • Thread starter Thread starter Kevin Johnston
  • Start date Start date
K

Kevin Johnston

I received help from Dmitry Streblechenko (thanks, Dmitry) on code I
made to copy and move a selected mail item from one folder to another,
apply a new MessageClass, and then open the the moved message with the
characteristics of the new MessageClass showing.

I am running into new problems when trying to do something essentially
the same, but this time just applying a new MessageClass to the
selected mail item in the current folder and then opening it with the
characteristics of the new class showing. It opens with the
characteristics of the old class. If thereafter I open it manually,
the new characteristics show. Here's relevant code:

~~~~~~~~~
Dim objApp As Application
Dim objFolder As Outlook.MAPIFolder
Dim objSelItem As MailItem
Dim strNewMC As String
Dim objSelection As Selection
Dim objNewItem As MailItem
Dim objNewMovedItem As MailItem
Dim objNS As Outlook.NameSpace
strNewMC = "IPM.Note.MyForm"

Set objFolder = GetFolder("Public Folders/My Folder")
Set objApp = CreateObject("Outlook.Application")
Set objSelection = objApp.ActiveExplorer.Selection
Set objNS = objApp.GetNamespace("MAPI")

'The following code works to move the item, apply the class, and
'open the item with the new characteristics:

Set objSelItem = objSelection.Item(1)
Set objNewItem = objSelItem.Copy
Set objNewMovedItem = objNewItem.Move(objFolder)
objNewMovedItem.MessageClass = strNewMC
objNewMovedItem.Save
strEntryID = objNewMovedItem.EntryID
strStoreID = objFolder.StoreID
Set objNewMovedItem = Nothing
Set objNewMovedItem = objNS.GetItemFromID(strEntryID, strStoreID)
objNewMovedItem.Display

'The following similar code does NOT work to apply the class
'to an item and then open it with the characteristics of the new
class:

Set objSelItem = objSelection.Item(1)
objSelItem.MessageClass = strNewMC
objSelItem.Save
strEntryID = objSelItem.EntryID
strStoreID = objFolder.StoreID
Set objSelItem = Nothing
Set objSelItem = objNS.GetItemFromID(strEntryID, strStoreID)
'Following displays item without new characteristics showing
objSelItem.Display

~~~~~~~~~~

Thanks to anyone who can help!!
 
Even though you dereference the item, Outlook still has it referenced, so
dereferencing doesn't do anything. I don't think there is anything you can
do.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top