How to find Appointment Item by EntryID?

D

deko

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
 
D

Dave Kane [MVP - Outlook]

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.Categories<>strCategoryName 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.Categories<>strCategoryName 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
 
D

deko

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.
 

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