Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Outlook with Access

Status
Not open for further replies.

Tweetiepie

Programmer
Jul 13, 2001
7
GB
Hi I have an access database. When someone clicks a button on the form to save the input it automatically launches mc outlook and sends an email to the administrator of the details entered by the user. Is there anyway using vba that i could close outlook after launching it or to see whether outloook is already launced and if it is then not to relaunch it.
 
This code here should only launch Outlook if it is not already open. Ensure that you have a reference set to the Microsoft Outlook library.

Dim appOutlook as Outlook.Application

On Error Resume Next
Set appOutlook = GetObject(,"Outlook.Application")
If Err.Number <> 0 Then
Set appOutlook = CreateObject(&quot;Outlook.Application&quot;)
Err.Clear
End If

On Error Goto ErrorHandler ...

To close Outlook, it should be as easy as using the following code.

appOutlook.Quit
Set appOutlook = Nothing
 
if you have an object variable pointed the outlook application use that instead of the following myOlapp object.
Insert into your code:

Dim myOlapp As Object
Set myOlapp = CreateObject(&quot;Outlook.Application&quot;)
myOlapp.Quit

or you can use &quot;findwindow&quot; api to find the application, after that you can quit it.

ide
 
IDE,
There's one little problem with your code. If you just use the CreateObject method, then a new instance of the object will always be created, even if an instance is already open. By checking if the application already exists (by using the GetObject method and checking for an error), you can get around this.
 
Neilkonitzer,
when i run this code all my outlook clients quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top