Delete or Replace Outlook Appointment

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
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi

Are you sure that you're capturing the correct EntryID in your database table? They should look something like this:

0000000063371390CC8BA54DB1FBFF673B306CA20700DD4CBE4A9353D04594C4691AB910A703005DE4B93B4F0000DD4CBE4A9353D04594C4691AB910A703005DE6FAD21D0000

Are those the sort of strings that you have in your database?

DK
 
Upvote 0
No I am not sure that I am capturing the ID correctly. No I don't have those type of strings in the DB. The appointment ID is an auto number and the one I am currently testing is a 3. Is this string generated by access? If so do you know how I can find it?

I have a 3 in the subject field of the Outlook Appointment, that 3 comes from my ApptID field on my Access table.

Thanks!
 
Upvote 0
OK, so you won't be able to use the GetItemFromID method unless you actually store the entry ID somewhere (in your Access table ideally as you wouldn't want such a long string in the subject field).

Alternatively, you could use your current solution but locate the appointment item by looping through all items in your mailbox and searching for one that has the "3" or whatever in the subject.

I personally would go for the first option as it is much more robust i.e. it's not going to break if someone comes along and deletes the number from the subject field.

HTH
DK
 
Upvote 0

Forum statistics

Threads
1,214,518
Messages
6,119,985
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top