Forum Discussion
Woldman
Apr 14, 2023Iron Contributor
Sample Access application for creating appointments in Outlook
Hello everyone, I received several requests for my sample Access application for creating appointments in Outlook, so I am sharing it here. The application The application automatically open...
Woldman
Feb 28, 2024Iron Contributor
I've also added functionality to delete an appointment from Outlook. In the sample application, you'll now find a delete button in addition to the add button.
This is the underlying code, which deletes an appointment if the subject and start date/time match:
Private Sub cmdDeleteFromOutlook_Click()
Dim xOL As Outlook.Application, itmAppoint As Outlook.AppointmentItem, colAppoint As Outlook.Items
Dim nmsOL As Outlook.NameSpace, fldOL As Outlook.MAPIFolder
Dim i As Integer
' Create the actual Outlook object and an object for the appointment to be deleted
Set xOL = New Outlook.Application
Set itmAppoint = xOL.CreateItem(olAppointmentItem)
Set nmsOL = xOL.GetNamespace("MAPI")
Set fldOL = nmsOL.GetDefaultFolder(olFolderCalendar)
' Loop over all appointments
Set colAppoint = fldOL.Items
For i = colAppoint.Count To 1 Step -1
Set itmAppoint = colAppoint.Item(i)
' Delete appointment if description and start data/time match
If Me.ActionDescription = itmAppoint.Subject And Format(Me.ActionDate, "yyyy-mm-dd") & " " & Format(Me.ActionTime, "hh:mm") = Format(itmAppoint.Start, "yyyy-mm-dd hh:mm") Then
itmAppoint.Delete
' Reset the checkbox
Me.AddedToOutlook = False
' Requery the form to show all data changes
Me.Requery
End If
Next
' Remove the objects to keep memory clean
Set itmAppoint = Nothing
Set colAppoint = Nothing
Set nmsOL = Nothing
Set fldOL = Nothing
Set xOL = Nothing
End Sub
This code also resets the 'Added to Outlook' flag in the Access database.
I hope this helps.
Tieme