How can I make Outlook close when sending is complete

z0001130

New member
Local time
Today, 06:01
Joined
May 16, 2011
Messages
8
Everyone,

I am using "MyOutlook.Quit" command to close the instance of Outlook that I created but...
because the vba ruins faster than Outlook sends the email, I get the warning from Outlook about there being unsent messages in your outbox, exit without sending etc.

I there a method of quitting Outlook where it waits for Outlook to finish, other than putting a loop in to delay Access for a few seconds.

Thanks,
John
 
I am using "MyOutlook.Quit" command to close the instance of Outlook that I created but...
because the vba ruins faster than Outlook sends the email, I get the warning from Outlook about there being unsent messages in your outbox, exit without sending etc.
I have never noticed that problem. One thing you could try is to hook the events of your mail item.

This means at the top of your form you would have this. You would then not declare your email item in your routine and you would call it outMail
Code:
Public WithEvents outMail As Outlook.MailItem

Once you do this you will notice that the VB editor will now show you all the events of outMail.

See if this event fires for you and if so check for this to fire before quiting outlook.

Code:
Public Sub outMail_Send(Cancel As Boolean)

End Sub
 
Thanks for that. I have to admit it is a little above my skill set.

On further analysis of the symptoms, it only happens when Outlook is already running. I did try to use the GetObject but I failed.

I then removed the oOutlook.Quit line and just left the oOutlook = Nothing and omail= nothing lines.

What happens now is that if it is already running, it leaves it running, if it opens a session of outlook, it closes it. Not quite sure why the code works that way, but more than happy that it leaves everythiong as it found it.
Thanks,
John
 
Thanks for that. I have to admit it is a little above my skill set.

On further analysis of the symptoms, it only happens when Outlook is already running. I did try to use the GetObject but I failed.

I then removed the oOutlook.Quit line and just left the oOutlook = Nothing and omail= nothing lines.

What happens now is that if it is already running, it leaves it running, if it opens a session of outlook, it closes it. Not quite sure why the code works that way, but more than happy that it leaves everythiong as it found it.
Thanks,
John

This is my understanding and I think good practice. Outlook is almost an "always on app" for people that have Outlook, so if you find it on dont turn it off.

If this works for you great. You can always come back here and take my suggestion. For example there might come a time when you want to know if the user actually sent the mail or not. Then you will have to implement what I have suggested.
 

Users who are viewing this thread

Back
Top Bottom