Private Sub Command89_Click()
Call subDeleteAutoGereratedAppointment(#2/16/2025 12:00:01 AM#, #2/16/2025 11:59:59 PM#, "user1@kosmosbusiness.onmicrosoft.com")
'Call subDeleteAutoGereratedAppointment(#2/16/2025 12:00:01 AM#, #2/16/2025 11:59:59 PM#, "user1@kosmosbusiness.onmicrosoft.com")
End Sub
Sub subDeleteAutoGereratedAppointment(dtmStart As Date, dtmEnd As Date, strOutlookEmail As String)
Dim olApp As Object
Dim nsMAPI As Object
Dim olAppointments As Object
Dim olFilterAppointments As Object
Dim olAppointmentItem As Object
Dim blnIsOutlookRunning As Boolean
Dim strDateRange As String
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Err.Clear
Set olApp = CreateObject("Outlook.Application")
blnIsOutlookRunning = False
Else
blnIsOutlookRunning = True
End If
On Error GoTo Error_Handler
DoEvents
Set nsMAPI = olApp.GetNamespace("MAPI")
Set olAppointments = nsMAPI.Folders(strOutlookEmail).Folders("Calendar")
Dim str123 As String
str123 = "123"
strDateRange = "[Start] >= '" & Format$(dtmStart, "mm/dd/yyyy hh:mm AMPM") _
& "' AND [Start] <= '" & Format$(dtmEnd, "mm/dd/yyyy hh:mm AMPM") & "' AND [Location] = '" & str123 & "' "
Set olFilterAppointments = olAppointments.Items.Restrict(strDateRange)
'Debug.Print olFilterAppointments.Count & " appointments found."
For Each olAppointmentItem In olFilterAppointments
olAppointmentItem.Delete
Next
If blnIsOutlookRunning = False Then
olApp.Quit
End If
Error_Handler_Exit:
On Error Resume Next
Set olAppointmentItem = Nothing
Set olFilterAppointments = Nothing
Set olAppointments = Nothing
Set nsMAPI = Nothing
Set olApp = Nothing
Exit Sub
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: GetFutureOutlookEvents" & vbCrLf & _
"Error Description: " & Err.Description _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub