Question : How to restrict on categories with recurrent items using VBA in access

Hi there,

I'm trying to fill a table in access with information about outlook appointments. All recurrent items should be added seperately.
I also want to filter (restrict) on 2 things: no all day event appointments (got that working without the restrict), and no appointments with a specific category ('geen kilometers').
The problem now is this: the restricting on categories works fine untill an appointment is recurring, then if just ignores it. However when i check this appointment, the categories property is the one that should be restricted.

In the code below i made a check. I do get the message "test", while all the appointments with this category should be gone. As mentioned before this only happens with recurrent appointments, normal appointments with this category do get filtered.

I would like to filter this from the objitems because in the loop i look at previous appointments in the list and therefore don't want to skip appointments in the loop.
Another solution would be to make the items from outlook in some sort of list, so i can remove items from it without removing them from the outlook calendar. So if you know how to do this i can work with that as well.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
Dim importDatum As Date
importDatum = DLookup("importDatum", "TblApp") 'the date from which the importing should start'
Dim ol As Object
Set ol = CreateObject("Outlook.Application")
Dim objitems As Variant
Set objitems = ol.GetNamespace("MAPI").GetDefaultFolder(9).Items
Dim c As Variant
objitems.Sort "[Start]"
objitems.IncludeRecurrences = True
Set objitems = objitems.Restrict("[Start] <= '" & Format(Date, "ddddd") & " 11:59 PM' AND [End] > '" & Format(importDatum, "ddddd") & " 12:00 AM'")
Set objitems = objitems.Restrict("not [Categories] = 'geen kilometers'")
'Set objitems = objitems.Restrict("[AllDayEvent] = False") 'this seems to remove all appointments always, but this can be fixed in the loop i use.

Dim counter As Integer
counter = 0
For Each c In objitems
    counter = counter + 1
    If c.categories = "geen kilometers" Then
        MsgBox ("test")
    End If
Next

Dim i As Integer
i = 1
Do While i <= counter
    Set c = objitems.Item(i)
    'do stuff'
Loop

Answer : How to restrict on categories with recurrent items using VBA in access

Hi, iandian.

You cannot use Restrict with Categories.  That is stated in the documentation for Restrict and Find both.  In fact Outlook should generate an error when attempting to Restrict on a prohibited field.
Random Solutions  
 
programming4us programming4us