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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

process keeps running after .Quit method

Status
Not open for further replies.

Eupher

MIS
Jul 18, 2002
1,724
US
I'm working on an Access 2k3 database that sends calendar appointments to Outlook 2k3. At the moment, the database consists of only one table and one form. On the form is a command button that creates the appointment and sends it to Outlook. But even though I'm using the .Quit method to close the instance of Outlook, and as far as I can tell am releasing all variables, the OUTLOOK.EXE process remains in task manager. Here's the code:
Code:
Private Sub cmdAddAppt_Click()
On Error GoTo Add_Err
[green]'Save record first to be sure required fields are filled.[/green]
DoCmd.RunCommand acCmdSaveRecord
[green]'Exit the procedure if appointment has been added to Outlook.[/green]
If Me!AddedToOutlook = True Then
    MsgBox "This appointment is already added to Microsoft Outlook"
    Exit Sub
    [green]'Add a new appointment.[/green]
    Else
        Dim objOutlook As Outlook.Application
        Dim objAppt As Outlook.AppointmentItem
        Dim myNameSpace As Outlook.NameSpace
        Dim myFolder As Outlook.MAPIFolder
        Dim myExplorer As Outlook.Explorer

        Set objOutlook = CreateObject("Outlook.Application")
        Set myNameSpace = objOutlook.GetNamespace("MAPI")
        myNameSpace.Logon "xyxyxyxyx", "zyzyzyzyz", False, True
        Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
        Set myExplorer = myFolder.GetExplorer
        Set objAppt = objOutlook.CreateItem(olAppointmentItem)

        With objAppt
            .Start = Me!ApptStartDate & " " & Me!ApptTime
            .Duration = Me!ApptLength
            .Subject = Me!Appt
            If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
            If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation
            .ReminderSet = False
            .Recipients.Add ("abcde@xyz.zyx")
            .Recipients.Add ("bcdef@xyz.zyx")
            .Recipients.Add ("cdefg@xyz.zyx")
            .Recipients.Add ("defgh@xyz.zyx")
            .Save
            Me!ApptID = .EntryID
            .Close (olSave)
        End With

        myExplorer.CommandBars("Menu Bar").Controls("Tools").Controls("Synchronize using SynQ").Execute

        [green]'Release explorer and folder variables[/green]
        Set myExplorer = Nothing
        Set myFolder = Nothing
        [green]'Log off[/green]
        myNameSpace.Logoff
        [green]'Release namespace variable[/green]
        Set myNameSpace = Nothing
        [green]'Release the AppointmentItem object variable.[/green]
        Set objAppt = Nothing
        [green]'Quit and release the application object variable.[/green]
        objOutlook.Quit
        Set objOutlook = Nothing
        [green]'Set the AddedToOutlook flag, save the record, display a message.[/green]
        Me!AddedToOutlook = True
        DoCmd.RunCommand acCmdSaveRecord
        MsgBox "Appointment Added!"
        Exit Sub
    End If
    
Add_Err:
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description
    Exit Sub
End Sub

I realize I can use the Win32 API to kill a process, but I would rather not - better to find why .Quit isn't getting the job done. Any clues? Thanks!

Ken S.
 
Could it be, you already had an instance running
of outlook?

I often use GetObject(), before CreateObject(),
in case an instance is running already.

If GetObject errors, I trap the error
using the CreateObject, then resume next.

Sub SendEmailTest()
10 On Error GoTo xxx

Dim appOutLook As Outlook.Application, itm As Object

20 Set appOutLook = GetObject(, Outlook.Application)
30 Set itm = appOutLook.CreateItem(olMailItem)


40 With itm
50 .To = fMyEmail
60 .Subject = "test" & Date
70 .Body = ""
'.Display
80 .Send
90 End With

100 appOutLook.Quit
xx:
110 Set appOutLook = Nothing
120 Set itm = Nothing
130 Exit Sub
xxx:
140 If err = 2501 Or err = 287 Then
150 Resume Next
160 ElseIf (err = 429 Or err = 462) Then ' activeX Component can not create object/Remote Server Machine does not exist or is unavailable
170 Set appOutLook = CreateObject("Outlook.Application")

190 Resume Next
200 Else
210 MsgBox err & vbCrLf & Error$ & vbCrLf & Erl
220 Resume xx
230 End If
End Sub
 
Hi, Zion7,

Thanks for the tip, that could prove useful. I've double-checked that there is no instance of OUTLOOK.EXE running prior to execution of the code. It seems an odd sequence of events is occuring:

1) code runs, appointment is posted, sync .Execute works normally
2) OUTLOOK.EXE process remains running in task manager
3) next time code runs, appointment is posted, sync .Execute line does NOT work (so appointment is not posted to Mirapoint server), OUTLOOK.EXE no longer appears in task manager.
4) Next time code runs just like 1) above, and so forth.

Ken S.
 
In case anyone's interested, I think I got to the bottom of this one. There are really 2 issues here:

1) OUTLOOK.EXE process remains running even after .Quit method

2) Code doesn't pause for dialogs raised by SynQ

The answer to #1 is to close the Explorer object before invoking the Quit method:
Code:
myExplorer.Close
objOutlook.Quit
The answer (or, more accurately, one possible answer) to #2 is to create a routine that enumerates running processes and searches for the SynQ title bar, then sets a boolean variable as appropriate, and loops as long as SynQ continues to be found (with a DoEvents to prevent CPU lock).

Maybe someone will find this useful...

Ken S.
 
Yes Ken, in answer to the first problem,
you're right (as I notice now), you were calling the
Set objOutlook = Nothing
AFTER the quit action.
So either Close or nothing, would have destroyed the instance, prior to Quitting...

Thanks for the update, on both issues!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top