Deleting an Appointment Record From Access to Outlook

L

Luman

I got great help in adding an appointment record from Access to Outlook
Calendar, following the event procedures from;
www.kbalertz.com/kb_160502.aspx
It worked just perfect.

Now I would like to remove (delete) an existing appointment from Access to
Outlook.
Could any one help me on this one?

Much Appreciated.
 
O

Ofer

This post was given by David C. Holley, try it


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
 
L

Luman

Hi Ofer,

Thanks for your reply. Sorry took so long to get back. Was on vacation.
I tried your suggestion but to no avail. I believe I will have to try to
capture the OutlookEntryID as you mentioned. How do I go about it?

Thanks for your time.
Lucien

Ofer said:
This post was given by David C. Holley, try it


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


--
I hope that helped
Good luck


Luman said:
I got great help in adding an appointment record from Access to Outlook
Calendar, following the event procedures from;
www.kbalertz.com/kb_160502.aspx
It worked just perfect.

Now I would like to remove (delete) an existing appointment from Access to
Outlook.
Could any one help me on this one?

Much Appreciated.
 
O

Ofer

Have you created reference to Microsoft Outlook?
Open code somewhere from the menu bar select tools > reference
and add Microsoft Outlook, and then try the code

--
I hope that helped
Good luck


Luman said:
Hi Ofer,

Thanks for your reply. Sorry took so long to get back. Was on vacation.
I tried your suggestion but to no avail. I believe I will have to try to
capture the OutlookEntryID as you mentioned. How do I go about it?

Thanks for your time.
Lucien

Ofer said:
This post was given by David C. Holley, try it


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


--
I hope that helped
Good luck


Luman said:
I got great help in adding an appointment record from Access to Outlook
Calendar, following the event procedures from;
www.kbalertz.com/kb_160502.aspx
It worked just perfect.

Now I would like to remove (delete) an existing appointment from Access to
Outlook.
Could any one help me on this one?

Much Appreciated.
 
Top