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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
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
 
L

Legacy 128378

Guest
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!
 

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,301
Messages
5,836,493
Members
430,436
Latest member
fefenouil

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
Top