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
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

dk

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

Watch MrExcel Video

Forum statistics

Threads
1,109,349
Messages
5,528,188
Members
409,807
Latest member
nicky736

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top