Outlook VBA, updating appointments

Ahmed

Outlook VBA, updating appointments

Post by Ahmed »

I wanted to update my appointments' start date, but I got the error "You don't have the permission to move this item", after tinkering with the code I found that recurring appointments cause this error, so the solution was updating recurrence pattern start date for recurring appointments instead of appointment start date. Here is a sample code:

Code: Select all

Private sub Update_Appointments
On Error GoTo Error_Handler
    Dim olFolder As Outlook.MAPIFolder
    Dim olAppoint As Outlook.AppointmentItem
    Dim kLoop As Integer
    Set olFolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
    kLoop = 1
    While kLoop <= olFolder.Items.Count
      Set olAppoint = olFolder.Items.Item(kLoop)
      If olAppoint.IsRecurring Then
          Dim myPattern As Outlook.RecurrencePattern
          Set myPattern = olAppoint.GetRecurrencePattern
          myPattern.PatternStartDate = #5/16/2005#
      Else
          olAppoint.Start = #5/16/2005#
      End If
      olAppoint.Save
      kLoop = kLoop + 1
    Wend
    Exit Sub
Error_Handler:
    MsgBox Err.Description
End Sub