none
Problem checking categories of retrieved Outlook Items RRS feed

  • General discussion

  • I got an issue related to Outlook Items. I would like to retrieve calendar items and check their categories. The problem is that Outlook.Items don't have the member Categories as AppointmentItems and MeetingItems. I want to check all Items which are of type AppointmentItems and MeetingItems. I get errors thrown and I was hoping that someone with the knowledge/experience could help me modify my code to accomplish my task.

    Here is my code to retrieve the calendar items, where olTemp and olItems both are of type Outlook.Items

    olTemp.Sort(

    "[Start]", False

    )

    olTemp.IncludeRecurrences =

    True

    olItems = olTemp.Restrict("[Start] >= " & Quote(dtStart & " 12:00 AM") & " AND [End] < " & Quote(dtEnd & " 11:59 PM "))

    But in the following code is were the problem is, I've tried different solutions and so far I got this. The current error is thrown at the IF-statement checking the categories.

    intCount = olItems.Count

     

    If intCount > 0

    Then

     

      For i = 1 To

    intCount

        olAppointment =

    CType(olFolder.Items.Item(Outlook.OlItemType.olAppointmentItem), Outlook.AppointmentItem

    )

        olAppointment =

    CType(olItems.Item(i), Outlook.AppointmentItem

    )

     

        If olAppointment.Categories.Equals("External") Or olAppointment.Categories.Equals("Internal") Or olAppointment.Categories.Equals("Available")

    Then

          blRetrieved =

    True

     

        Else

          olItems.Remove(i)

     

        End

    If

     

      Next

     

    End

    If

     

     

     

     
    ElreyBello
    Thursday, January 19, 2012 9:50 AM

All replies

  • I'm not sure how you decided that AppointmentItem or MeetingItem objects don't expose a Categories string property, it's right there as plain as day when you look at the Outlook object model in the Object Browser.
     
    In managed code an optional property such as Categories is null if no value was ever set for that property. So before checking for a value in Categories I would test for that condition:
     
    If (Not(IsStringNulOrEmpty(olAppointment.Categories))) Then
        Dim sCats As String = olAppointment.Categories
        If (sCats.Contains("External")) Then
                ' has the string as at least part of the categories
     

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "ElreyBello" <=?utf-8?B?RWxyZXlCZWxsbw==?=> wrote in message news:7fa79a1e-6d66-4bc2-a1be-24196f20f3c7...

    I got an issue related to Outlook Items. I would like to retrieve calendar items and check their categories. The problem is that Outlook.Items don't have the member Categories as AppointmentItems and MeetingItems. I want to check all Items which are of type AppointmentItems and MeetingItems. I get errors thrown and I was hoping that someone with the knowledge/experience could help me modify my code to accomplish my task.

    Here is my code to retrieve the calendar items, where olTemp and olItems both are of type Outlook.Items

    olTemp.Sort(

    "[Start]", False

    )

    olTemp.IncludeRecurrences =

    True

    olItems = olTemp.Restrict("[Start] >= " & Quote(dtStart & " 12:00 AM") & " AND [End] < " & Quote(dtEnd & " 11:59 PM "))

    But in the following code is were the problem is, I've tried different solutions and so far I got this. The current error is thrown at the IF-statement checking the categories.

    intCount = olItems.Count

     

    If intCount > 0

    Then

     

      For i = 1 To

    intCount

        olAppointment =

    CType(olFolder.Items.Item(Outlook.OlItemType.olAppointmentItem), Outlook.AppointmentItem

    )

        olAppointment =

    CType(olItems.Item(i), Outlook.AppointmentItem

    )

     

        If olAppointment.Categories.Equals("External") Or olAppointment.Categories.Equals("Internal") Or olAppointment.Categories.Equals("Available")

    Then

          blRetrieved =

    True

     

        Else

          olItems.Remove(i)

     

        End

    If

     

      Next

     

    End

    If

     

     

     

     
    ElreyBello

    Ken Slovak MVP - Outlook
    Thursday, January 19, 2012 3:05 PM
  • I never said that the AppointmentItems and MeetingItems didn't have Categories, even though I missed out on the 'do' in the end:

    'The problem is that Outlook.Items don't have the member Categories as AppointmentItems and MeetingItems (do).'

    Your check will be useful when I figure out how to convert my Outlook.Items to Outlook.AppointmentItems, until then I still have the same problem. And by the way, if I try to convert my Outlook.Item to an Outlook.AppointmentItem and its actually an Outlook.MeetingItem will that cause and error and if so how can I solve it?

     


    ElreyBello
    Thursday, January 19, 2012 3:40 PM
  • When you get an item from the Items collection you can cast it to an Appointment item using TryCast() and then check for a null item (Nothing). You can do the same with a cast to MeetingItem.
     
    Alternatively you can use Reflection to check on the Class property to check for 26 (OlObjectClass.olAppointment) or 53 (olMeetingRequest).
     
    Another approach might be to use code something like this:
     
        If TypeOf(oItems.Item(i)) Is Outlook.AppointmentItem Then
     
    Or you can get oItems.Item(i) as an Object and then use TypeOf() on the Object to test for MeetingItem or AppointmentItem.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "ElreyBello" <=?utf-8?B?RWxyZXlCZWxsbw==?=> wrote in message news:39b58e6b-2ede-4ce5-aae3-736d246a0292...

    I never said that the AppointmentItems and MeetingItems didn't have Categories, even though I missed out on the 'do' in the end:

    'The problem is that Outlook.Items don't have the member Categories as AppointmentItems and MeetingItems (do).'

    Your check will be useful when I figure out how to convert my Outlook.Items to Outlook.AppointmentItems, until then I still have the same problem. And by the way, if I try to convert my Outlook.Item to an Outlook.AppointmentItem and its actually an Outlook.MeetingItem will that cause and error and if so how can I solve it?

     


    ElreyBello

    Ken Slovak MVP - Outlook
    Thursday, January 19, 2012 3:53 PM
  • Thank you again Ken! The code below works for me.

    olAppointment =

    TryCast(olItems.Item(i), Outlook.AppointmentItem

    )

     

    If olAppointment Is Nothing

    Then

    olMeeting =

    TryCast(olItems.Item(i), Outlook.MeetingItem

    )

     

    If olMeeting Is Nothing

    Then

    olItems.Remove(i)

     

    Else

     

    If olMeeting.Categories.Equals("External") Or olMeeting.Categories.Equals("Internal") Or olMeeting.Categories.Equals("Available")

    Then

    blRetrieved =

    True

     

    Else

    olItems.Remove(i)

     

    End

    If

     

    End

    If

     

    Else

     

    If olAppointment.Categories.Equals("External") Or olAppointment.Categories.Equals("Internal") Or olAppointment.Categories.Equals("Available")

    Then

    blRetrieved =

    True

     

    Else

    olItems.Remove(i)

     

    End

    If

     

    End

    If


    ElreyBello
    Friday, January 20, 2012 8:52 AM