[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 748
  • Last Modified:

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.
0
QPR
Asked:
QPR
  • 3
  • 3
1 Solution
 
QPRAuthor Commented:
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
0
 
brd24gorCommented:
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?
0
 
brd24gorCommented:
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!
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
QPRAuthor Commented:
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?
0
 
brd24gorCommented:
http://support.microsoft.com/default.aspx?scid=kb;en-us;292796

If you have any global variables, they will not work in the Application_Quit() event as described above in the Microsoft KB article.  You may be trying to refer to a variable that has been destroyed.  If you have any global variables, try declaring them locally in the Application_Quit() event.  The article also suggests making a COM add-in, which I don't have much experience in.
0
 
QPRAuthor Commented:
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
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now