"Condition is not valid" error on Items.Find for Appointment Item using GlobalAppointmentID as filter

"Condition is not valid" error on Items.Find for Appointment Item using GlobalAppointmentID as filter

  • Comments 1

We are getting "Condition is not valid" error on Items.Find for Appointment Item using GlobalAppointmentID as filter.

We are using the filter as: strFilter = "[GlobalAppointmentID] = 'apptidhere'" and getting following exception:

runtime error '-2147352567(80020009)'  "Condition is not valid"

Then we have tried finding the Item using DSAL  query based on Proptag for GlobalAppointmentID  to avoid exception as below:

strFilter = "@SQL=""http://schemas.microsoft.com/mapi/id/{6ED8DA90-450B-101B-98DA-00AA003F1305}/00030102"" = 'ApptIDHere'"

but it would NOT return any Item as result because for both Jet and DASL queries, you cannot restrict on a binary property such as EntryID.

So, Binary properties are NOT SUPPORTED to Find or Restrict Outlook Items.

However, We can store GlobalAppointmentID in UserDefinedProperty to find item based on it using Find or Restrict as a workaround.

Here's what I have done in my sample VBA code and able to get Item from Items.Find using Custom Property :

NOTE: Following programming examples is for illustration only, without warranty either expressed or implied,
including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose.
This sample code assumes that you are familiar with the programming language being demonstrated and the tools used
to create and debug procedures.

   1:  'Creating Apptointment Item with Custom property.
   2:  Sub CreateTestAppointmentWithCustomProp()
   3:      Dim myOlApp As Outlook.Application
   4:      Dim myItem As Outlook.AppointmentItem
   5:      Set myOlApp = CreateObject("Outlook.Application")
   6:      Set myItem = myOlApp.CreateItem(olAppointmentItem)
   7:      myItem.Start = DateAdd("n", 16, Now)
   8:      myItem.End = DateAdd("n", 60, myItem.Start)
   9:      myItem.Subject = "TestAppointment"
  10:      myItem.ItemProperties.Add "GAI", olText, True
  11:      myItem.Save
  12:      myItem.ItemProperties.Item("GAI").Value = myItem.GlobalAppointmentID
  13:      myItem.Save
  14:      myItem.Display
  15:  End Sub
  16:   
  17:  'Finding Item based on Custom Property
  18:  Sub FindItem()
  19:          Dim objOutlook As Outlook.Application
  20:          Set objOutlook = New Outlook.Application
  21:          Dim objNS As Outlook.NameSpace
  22:          Set objNS = objOutlook.Session
  23:          Dim objFolder As Outlook.MAPIFolder
  24:          Set objFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
  25:          Dim objAppts As Outlook.Items
  26:          Set objAppts = objFolder.Items
  27:          Dim objAppt As Outlook.AppointmentItem
  28:          
  29:          Dim strFilter As String
  30:          strFilter = "@SQL=""http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/GAI"" = 'ApptIDHere'"
  31:       
  32:          Set objAppt = objAppts.Find(strFilter)
  33:          If objAppt Is Nothing Then
  34:              MsgBox ("Nothing Found")
  35:          Else
  36:              MsgBox ("Appt Found")
  37:          End If
  38:  End Sub

To get property tag of your custom property for your DASL query we can use MFCMAPI available @ http://www.codeplex.com/MFCMAPI.

I have also referred following articles:

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post