Link to home
Start Free TrialLog in
Avatar of QPR
QPRFlag for New Zealand

asked on

Application_Quit() not firing?

Hi I'm doing a bit of a tutorial - the super-easy guide to outlook object model - from MS
One of the "hands on" examples is supposed to fire off an email when the application_quit() event occurs.

The first time I tried to quit outlook I got an error stating that (ummm can't remember error and can't reproduce (sorry!)) but the debug button took me to the Set NewMail = ThisOutlookSession.CreateItem(olMailItem) line.

I changed nothing. Now I get no error but the sub is not run!
I've pasted the very simple sub below together with the _quit() call to the sub.
Outlook 2000 SR1 (Win2k) Exchange Client.
Thanks

Private Sub Application_Quit()
PollRestaurant
End Sub
-----
Sub PollRestaurant()
    Set NewMail = ThisOutlookSession.CreateItem(olMailItem)
    NewMail.Subject = "please open this email and make your lunch choice"
    NewMail.Body = "use the voting buttons to make your selection"
    NewMail.VotingOptions = "Subway; McDonalds; Kebab; KFC"
    Set receiverOfMyMail = NewMail.Recipients.Add("removed to fight spam")
    NewMail.Send
End Sub

the email address above is set to a valid account in real life.
the macro works fine if not invoked via the quit() event.
Avatar of QPR
QPR
Flag of New Zealand image

ASKER

have rediscovered the error dialogue when I quit Outlook:
"Internal application error"

Also forgot to mention that I click "enable" when I start Outlook and it warns me of resident macros
Avatar of brd24gor
brd24gor

What is your security setting set to in Outlook (Tools > Macros > Security)?  If it is set to High, you may want to try and bump it down to Medium or even Low if you have a virus scanner running.  Possibly this could be keeping Application_Quit() from running?
I recreated your problem and the security setting does appear to be the problem.  If you have your security set to High, it won't run the macro and won't prompt you at all.  If you have it set to Medium, Outlook will tell you there are macros and ask whether you want to disable or enable them, and if you click Enable, your Application_Quit() will run just fine.  However, Outlook will prompt you EVERY time you open it.  The Low security setting works like Medium except that you aren't prompted to enable macros.  They are automatically enabled.

Hope this helps!
Avatar of QPR

ASKER

if I set secuirty to "low" then it will fire *sometimes*
If I click the 'x' at the top right to exit Outlook then nothing. If I choose file-exit & log off then it will.
However it causes an "internal application error" and spews on this line:
 Set NewMail = ThisOutlookSession.CreateItem(olMailItem)

is the ThisOutlookSession session invalid for the application_quit event?
Meaning am I trying to refer to a session that has been closed/destroyed?
ASKER CERTIFIED SOLUTION
Avatar of brd24gor
brd24gor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of QPR

ASKER

thanks.
With this in mind I put the whole of the code in the quit() event rather than calling it.

Private Sub Application_Quit()
Set NewMail = ThisOutlookSession.CreateItem(olMailItem)
    NewMail.Subject = "please open this email and make your lunch choice"
    NewMail.Body = "use the voting buttons to make your selection"
    NewMail.VotingOptions = "Subway; McDonalds; Kebab; KFC"
    Set receiverOfMyMail = NewMail.Recipients.Add("me@home.com")
    NewMail.Send
End Sub

other than the reference to ThisOutlookSession everything is pretty much self contained yet the same error occurs "internal application error"
Outlook 2000