Re-opening message after MessageClass changed

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

Kevin Johnston

I am creating a macro that moves the presently selected mail item to a
public folder. It then applies the MessageClass of a custom mail form
in that folder so additional metadata fields are available. Finally,
it should open the message with the additional fields in that form
showing.

Everything works except the final step. When I use the Display
method, it still opens the message with the original form. If I
manually open the moved item, or open it with a separate macro, it
works fine, but not with the Display code in the original macro. Any
tips?

Here's part of the code:

Set objApp = CreateObject("Outlook.Application")
Set objSelection = objApp.ActiveExplorer.Selection
Set objSelItem = objSelection.Item(1)
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = GetFolder("Public Folders/All Public
Folders/MyFolder")
'(Using Sue Mosher's GetFolder function)

NewMC = "IPM.Note.MyForm"
If objSelItem.Class = olMail Then
Set objNewItem = objSelItem.Copy
Set objNewMovedItem = objNewItem.Move(objFolder)
Set objApp.ActiveExplorer.CurrentFolder = objFolder
objNewMovedItem.MessageClass = NewMC
objNewMovedItem.Save
'This is the only part that doesn't work:
objNewMovedItem.Display
End If

Thanks in advance!
 
Thanks, Dmitry. Actually, I got an error message when I tried it
(Run-time error '-1834737 (ffe4010f)': The operation failed.), but I
carried on your logic a bit further and added a reference to the
StoreID of the folder the item was being moved to:

objNewMovedItem.Save
strEntryID = objNewMovedItem.EntryID
strStoreID = objFolder.StoreID
Set objNewMovedItem = Nothing
Set objNewMovedItem = objNS.GetItemFromID(strEntryID, strStoreID)
objNewMovedItem.Display

Now it works fine. I guess Outlook needed more information where to
find the item since it had just been moved. Thanks for pointing me in
the right direction!
 
Back
Top