Removing an appointment from outlook using Access

  • Thread starter Thread starter Guest
  • Start date Start date
This SHOULD get you started. It assumes thought that the OutlookEntryID
was captured by Access and saved in a field for the record to which the
appointmentItem pertains. The function retrieves this value via a field
displayed on the form and then uses the .GetItemFromId method to grab it
in code and delete it. Let me know if you'd like to see the companion
SUB that creates teh appointment & captures the OutlookEntryId.

Sub deleteOutlookAppointment()

Dim objOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
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]![frmReservations]![txtOutlookEntryId] <> "" And
IsNull([Forms]![frmReservations]![txtOutlookEntryId]) = False Then
DoCmd.Hourglass (True)
[Forms]![frmReservations]![txtAdvisory] = "Accessing Outlook..."
[Forms]![frmReservations].Repaint
Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
On Error Resume Next
Set targetAppointment =
nms.GetItemFromID([Forms]![frmReservations]![txtOutlookEntryId])
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]![frmReservations]![txtOutlookEntryId] = Null
Call createOutlookAppointment
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
 
David, i think you might be able to help me out I have a task and Appointment
buttons I use in an Access DB and they work fine the problem is I have not
figured out how to capture the entries into an Access table which I think you
mentioned i need to use the EntryID. Can you send me a sample of that code.
The companion Sub you mentioned below I think is what I need. Thanks so much.


David C. Holley said:
This SHOULD get you started. It assumes thought that the OutlookEntryID
was captured by Access and saved in a field for the record to which the
appointmentItem pertains. The function retrieves this value via a field
displayed on the form and then uses the .GetItemFromId method to grab it
in code and delete it. Let me know if you'd like to see the companion
SUB that creates teh appointment & captures the OutlookEntryId.

Sub deleteOutlookAppointment()

Dim objOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
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]![frmReservations]![txtOutlookEntryId] <> "" And
IsNull([Forms]![frmReservations]![txtOutlookEntryId]) = False Then
DoCmd.Hourglass (True)
[Forms]![frmReservations]![txtAdvisory] = "Accessing Outlook..."
[Forms]![frmReservations].Repaint
Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
On Error Resume Next
Set targetAppointment =
nms.GetItemFromID([Forms]![frmReservations]![txtOutlookEntryId])
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]![frmReservations]![txtOutlookEntryId] = Null
Call createOutlookAppointment
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

How can i remove an appointmennt from an outlook calendar with a form in
access?
 
Back
Top