Finding Calendar Items

  • Thread starter Thread starter Randy Harris
  • Start date Start date
R

Randy Harris

I'm using a For...Next loop to sequence through each of the Appointments in
the Calendar.

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderCalendar)
For I = 1 to myFolder.Items.Count

Is there any way to reliably predict the sequence in which the appointments
will be returned (such as by Start date or sequence created or whatever)?
If the program knows the Start date, I'd rather not have to search through
all of the appointments to find it.

Any help is appreciated.
 
You should be able to use the .Restrict method to reduce the number of
Items to those on the specific date.
 
David C. Holley said:
You should be able to use the .Restrict method to reduce the number of
Items to those on the specific date.

After reading the docs for .Restrict I am beginning to think that I might be
going about this the wrong way. What I need to do is locate an
AppointmentItem in the MAPI folder that has a UserProperty set to a
particular value. Can that be done with the .Find method directly?
 
It took me a bit to get the syntax worked out but it now works nicely.
Thanks for the tip.

Randy
 
Always HATED .RESTRICT took a bit to get used to it. Here BTW is the SUB
that I use to snoop an AppointmentItem created from my Access DB.

Function deleteOutlookAppointmentByTransportId(lngTransportId As Long,
frm As Variant)

Dim objOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
Dim targetCalendar As Outlook.MAPIFolder
Dim targetItems As Outlook.Items
Dim i As Integer
Dim aOutlookEntryIds()
Dim appointmentCount As Integer
Dim targetAppointment As Outlook.AppointmentItem
Dim strFilter As String

Set objOutlook = CreateObject("Outlook.application")
Set nms = objOutlook.GetNamespace("MAPI")
Set targetCalendar = nms.GetDefaultFolder(olFolderCalendar)
strFilter = "[dbAccessId]=" & Chr(34) & lngTransportId & Chr(34)
Set targetItems = targetCalendar.Items.Restrict(strFilter)

ReDim aOutlookEntryIds(targetItems.Count)
For i = 1 To targetItems.Count
Debug.Print i
aOutlookEntryIds(i) = targetItems(i).EntryID
Next i

Select Case targetItems.Count
Case 0
Debug.Print "AppointmentItem not found."
deleteOutlookAppointmentByTransportId = 0
Case Else
Debug.Print targetItems.Count & " AppointmentItem(s) found.
Deleting all instances."
For i = 1 To targetItems.Count
Set targetAppointment =
nms.GetItemFromID(aOutlookEntryIds(i))
Debug.Print targetAppointment.UserProperties(1),
targetAppointment.Start, targetAppointment.Subject
targetAppointment.Delete
Debug.Print "Appoint ID: " & aOutlookEntryIds(i) & "
Deleted"
Debug.Print
Next i
deleteOutlookAppointmentByTransportId = -1
End Select

End Function
 
Back
Top