Searching Outlook Calendar Events

Started by MrLeadFoot, January 29, 2022, 04:51:22 PM

Previous topic - Next topic

MrLeadFoot

I am trying to find Outlook Calendar items that include text strings. I've come across two different issues, and wondering if someone can help shed some light on what might be going on.

For simplicity sake, I have provided the following snippets to try to convey my issues without cluttering up the post with too much code.

I am using the following to open the correct Outlook folder and get the Calendar Items:

olFolderCalendar = 9
objOutlook = ObjectOpen("Outlook.application")
objNameSpace = objOutlook.GetNameSpace("MAPI")
objFolder = objNameSpace.GetDefaultFolder(olFolderCalendar)
objCalendarItems = objFolder.Items


I establish a loop and perform the following search for each matching Calendar Item:

TextString="Test"
SearchCriteria = StrCat("[Subject]=","""",TextString,"""")
ItemFound=objCalendarItems.Find(SearchCriteria)

Message("Found Event",ItemFound)


I then close out of Outlook:

ObjectClose(objCalendarItems)
ObjectClose(objFolder)
ObjectClose(objNameSpace)
ObjectClose(objOutlook)


The above search returns items that contain only the word "Test" in the Subject field in an Outlook Calendar Item. If the Subject contains "Test Item", the search above does not return anything. Same thing happens if I search the Billing Information field. I'm wondering if the equal "=" sign that I use in the SearchCriteria variable above might only return an exact match. If that's the case, does anyone know what operator I might use instead of "=" to find a Subject that CONTAINS the word "Test"?

Here's the second issue I'm finding.  If I use the same method to search in the Body field of Calendar Items, like this:


TextString="Test"
SearchCriteria = StrCat("[Body]=","""",TextString,"""")
ItemFound=objCalendarItems.Find(SearchCriteria)

Message("Found Event",ItemFound)


nothing is ever found, even if the only word in the Body field in the Outlook Calendar Item is "Test". Is the Body field in Outlook Calendar Items of a particular format that prevents searching altogether? If not, what structure do I need to use in order to find all Calendar Items that include the word "test"?

Thank you.

stanl

Not sure if applicable but have you thought of maybe putting a date range restriction on the calendar events, looping through and extracting both subject and body, then using WB to search the text rather than .Find() method.  Just .02

MrLeadFoot

It's never "just. 02", because everything is valuable to me, and your suggestion is indeed perfectly applicable, so thank you for replying.

That said, since I posted my question, I discovered that for some reason MANY Outlook fields are NOT searchable, the Body field being one of them, which explains the second problem I was seeing, so now I know I'm not completely incapable, and actually pulled my hair out for quite some time trying to fix something that wasn't actually broken! :-\

Regarding your suggestion, that's exactly what I've been thinking of doing, except for the date range part. In case that I likely haven't thought this through as thoroughly as you, may I ask why you suggested a date range? Also, do you happen to have any sample code for this type of loop you can point me to? Thank you.

Off-topic P. S. I see your avatar is a German Shepherd. I take it you have one? What do you have? I used to train K9s (I still have a training business, just no longer K9s) , and have a GSD of my own.

MrLeadFoot

I found the sample in the Tech Database and was able to tweak it and make it work for my needs. Thanks so much for the suggestions, Stan!  :D

stanl

Quote from: MrLeadFoot on January 30, 2022, 08:49:17 AM
Off-topic P. S. I see your avatar is a German Shepherd. I take it you have one?


Beckett. Full bred GSD. Going on 10. Loves to open all the Christmas presents.

MrLeadFoot

Nice looking dog, Stan. Don't know if this is appropriate on this board, but below is a Frisbee action shot, and links to a couple of videos of my current 13.5 yr. old when she was 11 and 13 months that you might enjoy:



https://www.youtube.com/watch?v=jQ1N1wVMN6E

https://www.youtube.com/watch?v=1GalvVNYhUI