Searching Outlook Calendar

P

PeterM

Below I have code I found which goes thru my Outlook Calendar and searches
for items. As a test, I first tried to find the calendar entry based on the
subject, which worked fine. I next tried to find it based on the calendar
location, which worked fine. However, when I tried to find it based on the
calendar start, it never finds it. I've tried the following values but none
of them work.

#3/29/2010 9:15:00 AM#
"3/29/2010 9:15:00 AM"
#03/29/2010 09:15:00 AM#
(#3/29/2010 9:15:00 AM#)
"03/29/2010 09:15:00 AM"

I've also created a variable as a type of date, set it to the value and it
was still not recognized.

When I run the following code with the debug.print, it displays
3/29/2010 9:15;00 AM
but when I step thru the code it does not recognize the value. Can anyone
please tell me how to find the calendar entry based on the calendar start
date?

I would appreciate it very much

Dim objFolder As Outlook.MAPIFolder
Dim objExplorer As Outlook.Explorer
Dim objSubFolder As Outlook.MAPIFolder
Dim objCalenderItem As Outlook.AppointmentItem
For Each objFolder In Session.Folders
Set objExplorer = objFolder.GetExplorer()
For Each objSubFolder In objExplorer.CurrentFolder.Folders
If objSubFolder.DefaultItemType = olAppointmentItem Then
For Each objCalenderItem In objSubFolder.Items
If objCalenderItem.Subject = ("03/28/2010 09:15:00 AM")
Then
MsgBox objCalenderItem.Subject & ", " &
objCalenderItem.Location & " " & objCalenderItem.Start & " " &
objCalenderItem.End & " " & objCalenderItem.Body
' Debug.Print objCalenderItem.Subject & ", " &
objCalenderItem.Location & " " & objCalenderItem.Start & " " &
objCalenderItem.End & " " & objCalenderItem.Body
End If
Next
End If
Next
Next

Set objFolder = Nothing
Set objExplorer = Nothing
Set objSubFolder = Nothing
Set objCalenderItem = Nothing
 
P

PeterM

I discovered a mistake in the code I previously listed: the IF statement
looks like this.

If objCalenderItem.Start = ("03/28/2010 09:15:00 AM") Then
 
P

PeterM

Daryl...

Nope, still not working. It does find a match based on the calendar
subject. I have placed msgbox's all over the place and while the values in
the calendar for start and and the start from the access calendar are the
same the VBA code does not recognize the match. I'm pulling my hair out.

One thing I noticed... some calendar start's have a date only (3/29/2010)
and some have a date and time (3/29/2010 9:15:00 AM). What's up with than?
 
P

PeterM

Daryl...

I finally got it to work and I'm glad I had the problem. I was checking all
of the outlook calendar entries for each entry in my access calendar which
was taking forever to run (about 5-6 seconds). I changed it to load all
outlook calendar entries into a listbox upfront. Then I check each day from
the access calendar against all entries in the outlook calendar listbox.
It's now finding matching entries and runs much faster (about 2-3 seconds).

I appreciate your taking a look for me.

Peter
 
D

Daryl S

Glad it is working for you. By the way, the all-day events won't have a
time with them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top