Link to home
Start Free TrialLog in
Avatar of newbie46
newbie46

asked on

Retrieving Recurring Items from Outlook Calendar using VBA

I am using the following code to retrieve Outlook calendar items and store them into an Access 2007 table. This code works correctly for non-Recurring Items.

Private Sub RetrieveOutlookEntries_Click()
Dim OutObj As Outlook.Application        
Dim OutAppt As Outlook.AppointmentItem      
Dim OutItems As Outlook.Items
Dim ItemFilter As Variant

Set OutObj = CreateObject("Outlook.Application")
Set objNS = OutObj.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(olFolderCalendar)
Set OutItems = objFolder.Items

OutItems.Sort "[Start]"

For Each OutAppt In OutItems
  If OutAppt.Start >= "1/1/2013" And OutAppt.Start <= "1/25/2013" Then
    db.execute "INSERT INTO TempOutlookEntries ( ) VALUES ()
  End If
 
Next

Set OutAppt = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set OutObj = Nothing
End Sub

1) Are the following statements causing the Recurring Items to not be included?
Dim OutAppt As Outlook.AppointmentItem      
Dim OutItems As Outlook.Items

2) Does additional code need to be added to process the Recurring Items?

Thanks.
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Set OutItems = objFolder.Items

 outItems.IncludeRecurrences = True     '  add this line


OutItems.Sort "[Start]"
Avatar of newbie46
newbie46

ASKER

capricorn1,

With that added statement, the code continuously loops through:

For Each OutAppt In OutItems
  If OutAppt.Start >= "1/1/2013" And OutAppt.Start <= "1/25/2013" Then
    db.execute "INSERT INTO TempOutlookEntries ( ) VALUES ()
  End If

When I break to stop the code from executing, click Debug and then hit F8, it is still cycling through the If - End If.

The execution never ends. Is there a way to limit the OutItems that it is processing?
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, capricorn1. That worked!!