MailItem.Save() causes -2147221239 (object changed) error

P

PuppetMaster

I am writing a VB6 Com Add-in for Outlook 2002 with Exchange accounts.
Essentially, I am just altering the subject line and then resaving the
mail object. However, for some users they receive an error: "The
function cannot be performed because the message has been changed".

I have also now trapped this error, reloaded the object, make the
subject line change and resave the object - all within a few lines of
code - but the error can still occur!

More peculiar, is that it only seems to affect certain Exchange
accounts and is not machine specific - for one user it works fine, but
a different user logs on to the same machine and it doesn't work.

Any help would be greatly appreciated!!


Below is a code extract: -

On Error GoTo writeProblem
failedSaves = 0
saveIt:
itemObj.subject = newSubject
itemObj.Save
myLogger.log "Saved local object with subject change"
itemObj.subject = mails.removeMailFlag(itemObj.subject)
Call itemObj.SaveAs(frmSaveMail.dd_saveDir.Value & "\" &
projectFilename)
myLogger.log "Mail saved to " & frmSaveMail.dd_saveDir.Value & "\"
& projectFilename

[snip]

writeProblem:
Set itemObj = Nothing
If Err.Number = -2147221239 Then 'Object has changed
failedSaves = failedSaves + 1
myLogger.log "ERROR[" & CStr(failedSaves) & "]: saveMail():
Could not save to " & frmSaveMail.dd_saveDir.Value
myLogger.log Err.Number & ", " & Err.Description
If failedSaves < 10 Then
Set itemObj =
oApp.GetNamespace("MAPI").GetItemFromID(mailID)
myLogger.log "Going to retry saving."
Resume saveIt
Else
myLogger.log "Failed too many times! Giving up."
End If
End If
 
A

Alex

I don't actually know why is it raising the error. However, I think there is
a workaround for this.
Use Copy() method for the mailItem object. You make a new copy of the
mailitem, change the subject and save/move the item to new place. Always
leave the orginial mail alone so that Outlook can send it without raising an
error.

Hope that helps,
Alex
 
P

PuppetMaster

Thanks for the workaround idea, Alex. However, I think I narrowed the
problem down to my having two separate references open to the same
object at the same time. I now occassionally still get the error, but
once I drop and reload the mailItem, it always successfully saves the
second time.

Still have absolutely no idea why it only affects certain users though!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top