Solved

Retrieving Recurring Items from Outlook Calendar using VBA

Posted on 2013-01-25
4
720 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

734 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