Link to home
Start Free TrialLog in
Avatar of Mitch Schwartz
Mitch Schwartz

asked on

Outlook Automation in Access Using "Find"

I am trying to use VBA Automation in Access 2013 to find and open appointments using filter criteria. The code "finds" the appointment, but when I try to open the found appointment (in Outlook) I get Error 91 ("Object variable not set"). The error occurs when I use the .Display method of the Appointment object. Here's the code:

Sub FindOutlookAppt()
  Dim olApp As Outlook.Application
  Dim objAppointment As Outlook.AppointmentItem
  Dim objAppointments As Outlook.MAPIFolder
  Dim objNameSpace As Outlook.NameSpace
  Dim objProperty As Outlook.UserProperty
  Dim OutlookStartTime, OutlookEndTime As Date
  Dim sFilter As Variant
  
  Set olApp = CreateObject("Outlook.Application")
  Set objNameSpace = olApp.GetNamespace("MAPI")
  Set objAppointments = objNameSpace.GetDefaultFolder(olFolderCalendar)
  
  sFilter = "[Subject] = '" & "Workout" & "'"
  
  Set objAppointment = objAppointments.Items.Find(sFilter)
  objAppointment.Display
  
  Set objAppointment = Nothing
  Set objAppointments = Nothing

End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Karl Timmermans (Outlook MVP 2012-2018)
Karl Timmermans (Outlook MVP 2012-2018)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mitch Schwartz
Mitch Schwartz

ASKER

Your suggestion solved it, Karl! When I added the check for a successful "Find", it showed me where I went wrong.