Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Retrieving Recurring Items from Outlook Calendar using VBA

Posted on 2013-01-25
4
Medium Priority
?
728 Views
Last Modified: 2013-01-26
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.
0
Comment
Question by:newbie46
  • 2
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38821014
Set OutItems = objFolder.Items

 outItems.IncludeRecurrences = True     '  add this line


OutItems.Sort "[Start]"
0
 

Author Comment

by:newbie46
ID: 38821257
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?
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 38821460
Private Sub RetrieveOutlookEntries_Click()
Dim OutObj As Outlook.Application        
Dim OutAppt As Outlook.AppointmentItem      
Dim OutItems As Outlook.Items
Dim ItemFilter As Variant

Dim outItemsInDateRange As Outlook.Items
Dim strRestriction As String
Dim outFinalItems As Outlook.Items

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

outItems.IncludeRecurrences = True

strRestriction = "[Start] >= '1/1/2013' AND [End] <= '1/25/2013'"

OutItems.Sort "[Start]"

Set outItemsInDateRange = outItems.Restrict(strRestriction)
Set outFinalItems = outItemsInDateRange

outFinalItems.Sort "[Start]"

For Each OutAppt In OutFinalItems
  '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
0
 

Author Comment

by:newbie46
ID: 38822501
Thank you, capricorn1. That worked!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Take a look at these 6 Outlook Email management tools which can augment the working and performance of Microsoft Outlook to give you a more rewarding emailing experience.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question