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:
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.
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.