Solved

Retrieving Recurring Items from Outlook Calendar using VBA

Posted on 2013-01-25
4
717 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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero earned 500 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now