Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   How to find Appointment Item by EntryID? (http://www.outlookbanter.com/outlook-vba/7296-how-find-appointment-item-entryid.html)

deko January 23rd 06 05:27 AM

How to find Appointment Item by EntryID?
 
When looping through a collection of Outlook.Items that includes
recurrences, and a recurring appointment is found, I need to get the
non-recurring appointment in order to change the Categories property.

I want to eliminate the the Do loop below and go directly to the appointment
item in question. I can minimize the iterations of the loop by restricting
the olRitms collection with strFilter, but there must be a way to get the
item by EntryID (?) Any suggestions appreciated...

For Each outlook appointment item including recurrences...

If olai.IsRecurring Then
strEntryID = olai.EntryID
Set olRitms = olns.GetDefaultFolder(olFolderCalendar).Items
Set objRcr = olRitms.Restrict(strFilter)
Do While i objRcr.Count
i = i + 1
If objRcr(i).EntryID = strEntryID Then
objRcr(i).Categories = strCategoryName
objRcr(i).Save
End If
Loop
End If

Next



Dave Kane [MVP - Outlook] January 23rd 06 06:15 PM

How to find Appointment Item by EntryID?
 
It sounds like you want to change the Categories value for all the
occurrences in a series - is that right? In that case you need to make the
change to the recurrence master. I assume from your description that "olai"
is obtained by iterating through an Items collection where
IncludeRecurrences = True.

Dim apptMaster as AppointmentItem

If olai.IsRecurring Then
Select Case olai.RecurrenceState
Case olApptMaster
'this is the recurrence master
'set Categories value here (if necessary)
If olai.Categories strCategoryName Then
olai.Categories = strCategoryName
olai.Save
End If
Case olApptOccurrence
'this is just a regular occurrence in the series
'don't make a change here or you will make this an exception
'all occurrences in the series will have the same EntryID value
'calling GetItemFromID with that value will return the
recurrrence master
Set apptMaster = olns.GetItemFromID(olai.EntryID)
If apptMaster.CategoriesstrCategoryName Then
apptMaster.Categories = strCategoryName
apptMaster.Save
End If
Case olApptException
'this is an exception to the series
'it can have property values that are different from the master
If olai.CategoriesstrCategoryName Then
olai.Categories = strCategoryName
olai.Save
End If
Case Else
'the other possible value is olApptNotRecurring, which won't be
returned if IsRecurring = True
End Select
End If


"deko" wrote in message
...
When looping through a collection of Outlook.Items that includes
recurrences, and a recurring appointment is found, I need to get the
non-recurring appointment in order to change the Categories property.

I want to eliminate the the Do loop below and go directly to the
appointment item in question. I can minimize the iterations of the loop
by restricting the olRitms collection with strFilter, but there must be a
way to get the item by EntryID (?) Any suggestions appreciated...

For Each outlook appointment item including recurrences...

If olai.IsRecurring Then
strEntryID = olai.EntryID
Set olRitms = olns.GetDefaultFolder(olFolderCalendar).Items
Set objRcr = olRitms.Restrict(strFilter)
Do While i objRcr.Count
i = i + 1
If objRcr(i).EntryID = strEntryID Then
objRcr(i).Categories = strCategoryName
objRcr(i).Save
End If
Loop
End If

Next





deko January 23rd 06 07:15 PM

How to find Appointment Item by EntryID?
 
It sounds like you want to change the Categories value for all the
occurrences in a series - is that right? In that case you need to make the
change to the recurrence master. I assume from your description that
"olai" is obtained by iterating through an Items collection where
IncludeRecurrences = True.


Yes - my code is automation from Access. I get a collection of
Outlook.Items and loop through it to update each appointment's Categories
property. What I was missing was an understanding of the RecurrenceState
method. Now my code looks like this:

Dim olai as Outlook.AppointmentItem

For each olai in olItems

If olai.Categories strNewCategoryName Then
If olai.IsRecurring Then
If olai.RecurrenceState = olApptMaster Then
olai.Categories = strNewCategoryName
End If
Else
olai.Categories = strNewCategoryName
End If
End If

Next

The GetItemFromID method was what I was looking for in my original post, but
thanks to Dmitry Streblechenko's reply to a different post, I'm not sure I
need it for this procedure.

Thanks for the tip nonetheless.




All times are GMT +1. The time now is 07:50 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com