Search code examples
vbams-accessoutlookexchange-server

Make Outlook AppointmentItem Read-Only


I am creating outlook appointment items programmatically using VBA in MS Access and the Outlook Object Model (though the language shouldn't matter).

Items are added to multiple calendars belonging to a single user that other users are given read/write permissions to. The users have no reason to create or edit appointments on the calendar using Outlook. Appointment data is then stored in backend tables. Essentially, Outlook is being used as my "calendar view."

I am having major issues, however, with users changing appointment items directly in Outlook, which in turn do not update in my backend.

I would love an updateable "ReadOnly" property that can be set per appointment item and that disallows changes unless set back to False...but don't think one exists. Any suggestions?

Things I've tried or dismissed as solutions:

  • Reminding users of the rules.
  • Script that finds all mismatched items - this works but is not practical.
  • Custom Outlook form that doesn't allow edits - doesn't prevent users from dragging appointment around.

UPDATE: Using the suggestion by nemmy below, I have manged to get this far. This only works if the user selects the appointment before changing anything. It does not work if the appointment is selected and dragged in the same click.

Private WithEvents objExplorer As Outlook.Explorer
Private WithEvents appt As Outlook.AppointmentItem

Public Sub Application_Startup()
Set objExplorer = Application.ActiveExplorer
End Sub

Private Sub objExplorer_SelectionChange()
 If objExplorer.CurrentFolder.DefaultItemType = olAppointmentItem Then
    If objExplorer.Selection.Count > 0 Then
      Set appt = objExplorer.Selection(1)
    End If
  End If
End Sub


Private Sub appt_Write(Cancel As Boolean)
If Not appt.Mileage = "" Then 'This appointment was added by my program
    MsgBox ("Do not change appointments directly in Outlook!")
    Cancel = True
    appt.Close (olDiscard)
End If
End Sub

Solution

  • Can you hook into the Write Event of appointment items? You could prevent changes being made that way. Something like below might work (Disclaimer not tested):

    Public WithEvents myItem As Outlook.AppointmentItem 
    
    Sub Initialize_handler() 
    
     Set myItem = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Items("Your Appointment") 
    
    End Sub 
    
    
    
    Private Sub myItem_Write(Cancel as boolean) 
    
      Cancel=true 
    
    End Sub