QPR
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.CreateI tem(olMail Item) 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.CreateI tem(olMail Item)
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("re moved 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.
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.CreateI
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.CreateI
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("re
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.
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!
Hope this helps!
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.CreateI tem(olMail Item)
is the ThisOutlookSession session invalid for the application_quit event?
Meaning am I trying to refer to a session that has been closed/destroyed?
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.CreateI
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.CreateI tem(olMail Item)
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
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.CreateI
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
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
ASKER
"Internal application error"
Also forgot to mention that I click "enable" when I start Outlook and it warns me of resident macros