I am having a problem with a calendar in Outlook 2010 that is driving me nuts. I am fairly new to both Outlook and VBA, so I might be overlooking something fairly obvious. However, after much research and testing I have not found a solution.
Using Excel VBA I have added birthdays to an Outlook 2010 calendar as all day appointments (start time 12:00 AM on starting day and end 12:00 AM on following day). When I subsequently try to find the appointment using the following filter, the program returns nothing for that date (in the example, 14.10.2018 should contain 1 appointment):
Dim dAppDate as Date
dAppDate = "14.10.2018"
sFilter = "[Start] = '" & Format$(dAppDate, "dd.mm.yyyy") & "'"
Set onamespace = oApp.GetNamespace("MAPI")
Set oFolder = onamespace.GetDefaultFolder(olFolderCalendar)
Set oItems = oFolder.Items
Set oFilterAppointments = oItems.Restrict(sFilter)
If, however, I just change the filter slightly as follows:
sFilter "[Start] >= '" & Format$(dAppDate, "dd.mm.yyyy") & "'"
I get all appointments AFTER 14.10.2018, but not the one for that date. Any ideas? This is driving me bats..I have also tried including the start time (12:00 AM) in the filter, but that brought no joy either. Any ideas will be more than appreciated.
I think there are two issues:
=
operator to work when searching for dates, so I tried a combined filter and that worked: sFilter = "[Start] > '" & Format(dAppDate - 1, "yyyy/mm/dd") & "'" & " AND [End] < '" & Format(dAppDate + 1, "m/d/yyyy") & "'"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.