Prevent automatic save of mailitem

G

Guest

Hi,

I want to modify the mailitem's htmlbody, open the
mailitem showing the modified message and when I close
the mailitem, I don't want the changes to persist.

Unfortunately each time I close the mail, outlook
automatically seems to save the changes. The write event
never even gets triggered before the close event , infact
it never gets triggered.

Anyone has any ideas on how I can prevent the automatic
save programatically?

Thanks,
Juhi.
 
K

Ken Slovak - [MVP - Outlook]

If you add code to the Item_Close event handler that closes the item
using the olDiscard argument does that work? Are you using the Outlook
editor or WordMail to read the HTML items? If using WordMail you'd
need to use code in the Word template.
 
J

Jbhan

Hi Ken,

I am using the Outlook editor to read items. Actually I
want to do and find and highlight text in a mail item. So
I am basically changing the html body of the email when
it is opened in a new inspector.
Once the user closes the inspector window I don't want
the changes to persist.
I never explicitly call the close method of the inspector
so I can't use the olDiscard param.
Can you tell me how I could handle the 'not save
mailitem' issue by using the close event..or is there any
other way to do it?

Appreciate your response!

Thanks,
Jbhan
 
K

Ken Slovak - [MVP - Outlook]

In the NewInspector event instantiate a MailItem that has been
declared WithEvents from Inspector.CurrentItem. That will let you
handle the MailItem.Close event. You can also handle the Write event
to cancel that if the user tries to save the item.

Even better would be an Inspector wrapper collection that wraps
Inspectors in custom Inspector wrapper class modules. That way you can
handle events for items if the user opens more than 1 item at a time.

The ItemsCB COM addin example on the Resources page at
www.microeye.com shows an Explorer wrapper that can be modifed and
used as an Inspector wrapper. Also you can Google for various posts
that I've made showing Inspector wrappers.
 
J

jbhan

Thanks a ton for your time and help!
But I am having a problem ...mainly that the close event
of the mailitem happens before the close event of the
inspector as a result it saves the changes to the
mailitem automatically. By the time the close method of
the mailitem is called in the inspector_close event the
mailitem has already been saved in its close event.



public static void Inspector_Close()
{

OutlookSession.MailItem = (Outlook.MailItemClass)
OutlookSession.OutlookInspectorClass.CurrentItem);

OutlookSession.MailItem.Close
(Outlook.OlInspectorClose.olDiscard);
}


public static void olInspectors_NewInspector
(Outlook.Inspector NewInspector)
{
OutlookSession.OutlookInspectorClass =
(Outlook.InspectorClass) NewInspector;

OutlookSession.MailItem =(Outlook.MailItemClass)
NewInspector.CurrentItem;
}


public static void MailItem_Close(ref bool Cancel)
{
Cancel = true;
}
}
 
K

Ken Slovak - [MVP - Outlook]

If you have instantiated a MailIem declared WithEvents, either in an
Inspector wrapper or when NewInspector fires you will get the
MailItem.Close event you want. I do that all the time. I myself use
Inspector wrappers because you never know when a user is going to have
more than 1 item open at a time.
 
G

Guest

Thanks Ken for all the help!
I finally adopted a different method to highlight text in
the mail item but I'll keep your suggestions in mind for
future problems.

jbhan.
 

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

Top