L
Legacy 128378
Guest
I am try to use the below code to delete an Outlook Appointment from Access 2010. I have the Appointment Table ID set to ApptID and it is captured on the Outlook Appointment Subject Field.
When I run this code I get the last error message "An Outlook appointment has not been scheduled for this reservation."
I seem to not be capturing the focus on the Outlook Appointment??
Thanks!
Dim mailbox As MAPIFolder
Dim targetCalendar As MAPIFolder
Dim targetAppointmentGroup As Outlook.Items
Dim targetAppointment As Outlook.AppointmentItem
Dim i
Dim flgAppointmentFound As Boolean
Dim strLocation As String
Dim strPrimaryPassenger As String
Dim strMsgBoxText As String
If [Forms]![Appointment Schedule]![ApptID] < "" And IsNull([Forms]![Appointment Schedule]![ApptID]) = False Then
DoCmd.Hourglass (True)
[Forms]![Appointment Schedule]![ApptID] = "Accessing Outlook..."
[Forms]![Appointment Schedule].Repaint
Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
On Error Resume Next
Set targetAppointment = nms.GetItemFromID([Forms]![Appointment Schedule]![ApptID])
If Err.Number = 0 Then
targetAppointment.Delete
MsgBox ("Outlook appointment deleted.")
Set targetAppointment = Nothing
Set nms = Nothing
Set objOutlook = Nothing
Else
strMsgBoxText = ""
strMsgBoxText = strMsgBoxText & "Unable to delete Outlook Appointment. " & Chr(13) & Chr(13)
strMsgBoxText = strMsgBoxText & Err.Description & Chr(13) & Chr(13)
strMsgBoxText = strMsgBoxText & "Create new Outlook Appointment?"
If MsgBox(strMsgBoxText, vbYesNo) = vbYes Then
[Forms]![Appointment Schedule]![ApptID] = Null
End If
DoCmd.Hourglass (False)
Exit Sub
End If
Else
MsgBox ("An Outlook appointment has not been scheduled for this reservation.")
End If
DoCmd.Hourglass (False)
End Sub
When I run this code I get the last error message "An Outlook appointment has not been scheduled for this reservation."
I seem to not be capturing the focus on the Outlook Appointment??
Thanks!
Dim mailbox As MAPIFolder
Dim targetCalendar As MAPIFolder
Dim targetAppointmentGroup As Outlook.Items
Dim targetAppointment As Outlook.AppointmentItem
Dim i
Dim flgAppointmentFound As Boolean
Dim strLocation As String
Dim strPrimaryPassenger As String
Dim strMsgBoxText As String
If [Forms]![Appointment Schedule]![ApptID] < "" And IsNull([Forms]![Appointment Schedule]![ApptID]) = False Then
DoCmd.Hourglass (True)
[Forms]![Appointment Schedule]![ApptID] = "Accessing Outlook..."
[Forms]![Appointment Schedule].Repaint
Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
On Error Resume Next
Set targetAppointment = nms.GetItemFromID([Forms]![Appointment Schedule]![ApptID])
If Err.Number = 0 Then
targetAppointment.Delete
MsgBox ("Outlook appointment deleted.")
Set targetAppointment = Nothing
Set nms = Nothing
Set objOutlook = Nothing
Else
strMsgBoxText = ""
strMsgBoxText = strMsgBoxText & "Unable to delete Outlook Appointment. " & Chr(13) & Chr(13)
strMsgBoxText = strMsgBoxText & Err.Description & Chr(13) & Chr(13)
strMsgBoxText = strMsgBoxText & "Create new Outlook Appointment?"
If MsgBox(strMsgBoxText, vbYesNo) = vbYes Then
[Forms]![Appointment Schedule]![ApptID] = Null
End If
DoCmd.Hourglass (False)
Exit Sub
End If
Else
MsgBox ("An Outlook appointment has not been scheduled for this reservation.")
End If
DoCmd.Hourglass (False)
End Sub