Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:32:16+00:00 2026-06-11T22:32:16+00:00

I have been trying to get appointments from outlook via the Outlook interop classes.

  • 0

I have been trying to get appointments from outlook via the Outlook interop classes. Specifically those that are reoccurring appointments. I have tried using both v12 and v14 of the interop libraries with the same results. The following code always results in the same exception for me.

Code:

Dim pattern As Outlook.RecurrencePattern = appt.GetRecurrencePattern()
Dim recur As Microsoft.Office.Interop.Outlook.AppointmentItem = Nothing
recur = rp.GetOccurrence(Now())

Exception:

You changed one of the recurrences of this item, and this instance no
longer exists. Close any open items and try again.

Note: I have used different values for the parameter to GetOccurrence, I am only using “now()” to simplify the code/problem. So I don’t believe the problem lies in using Now(). I tried DateTime.Parse(“8/28/2012”) or DateTime.Parse(“8/28/2012 5:00pm”) with the name exception being thrown.

I have looked at samples from here: Question 1, Question 2. Neither seem to have the same problem. I have tried every permutation of closing objects, releasing them, and nulling (nothing) them out. (e.g. Microsoft Office Interop – Tricks and Traps). I coppied and pasted examples directly from MSDN (ex: MDSN) with the same results. I am totally out of ideas!

I am running on Windows Server 2008 R2 64bit OS, Using Visual Studio 2010, .NET 4.0, with Outlook 2007.

Here is a more complete code example which always throws the exception for me:

    Public Sub TestOutlook()
    Dim oApp As Outlook.Application = Nothing
    Dim mapiNamespace As Outlook.[NameSpace] = Nothing
    Dim calFolder As Outlook.MAPIFolder = Nothing
    Dim calItems As Outlook.Items = Nothing

    oApp = New Outlook.Application()
    mapiNamespace = oApp.GetNamespace("MAPI")
    calFolder = mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
    calItems = calFolder.Items
    calItems.IncludeRecurrences = True

    For itemIndex As Integer = 1 To calItems.Count

        Dim item As Outlook.AppointmentItem = Nothing
        item = calFolder.Items.Item(itemIndex)

        If item.IsRecurring Then
            Dim rp As Outlook.RecurrencePattern = Nothing
            rp = item.GetRecurrencePattern()
            item.Close(Outlook.OlInspectorClose.olDiscard)
            CleanUpComObject(item)
            item = Nothing
            GC.Collect()

            Try
                rp.GetOccurrence(Now)
            Catch ex As System.Exception
                Debug.WriteLine("Ex with GetOccurrence: " & ex.Message)
            End Try

        End If
        If item IsNot Nothing Then item.Close(Outlook.OlInspectorClose.olDiscard)
        CleanUpComObject(item)
        item = Nothing
        GC.Collect()
    Next

    CleanUpComObject(calItems)
    CleanUpComObject(calFolder)
    CleanUpComObject(mapiNamespace)
    oApp.Quit()
    CleanUpComObject(oApp)
    GC.Collect()
End Sub

Private Sub CleanUpComObject(obj As Object)
    Try
        If obj IsNot Nothing AndAlso System.Runtime.InteropServices.Marshal.IsComObject(obj) Then
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj)
            obj = Nothing
        End If
    Catch ex As System.Exception
        Debug.WriteLine("Exception in Clean up: " & ex.Message)
    End Try
End Sub

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:32:17+00:00Added an answer on June 11, 2026 at 10:32 pm

    I’ve been struggling with exactly the same issue for the last couple of hours, and finally I have arrived at a solution. It seems as though GetOccurrence() always throws that error unless the DateTime value that is passed matches an instance of the recurring appointment – and the thing that caught me out was that the DateTime value has to match on both Date AND Time.

    Here’s a version of your code that takes the time from the RecurrencePattern and adds it to the DateTime value passed to GetOccurence(), which then should correctly find any instance of the appointment that falls on the selected date.

    Dim item As Outlook.AppointmentItem = Nothing 
    item = calFolder.Items.Item(itemIndex) 
    
    If item.IsRecurring Then 
        Dim rp As Outlook.RecurrencePattern = Nothing 
        rp = item.GetRecurrencePattern() 
    
        Dim dt2 as DateTime = DateTime.Parse("8/28/2012")
        dt2 = dt2.AddHours(item.Start.Hour)
        dt2 = dt2.AddMinutes(item.Start.Minute)
        dt2 = dt2.AddSeconds(item.Start.Second)
    
        item.Close(Outlook.OlInspectorClose.olDiscard) 
        CleanUpComObject(item) 
        item = Nothing 
        GC.Collect()  
    
        Try 
            rp.GetOccurrence(dt2)
    
        Catch ex1 As System.Runtime.InteropServices.COMException
    
    // Do Nothing, let this error go.  No instance of the appointment falls on this date.
    
        Catch ex As System.Exception
            Debug.WriteLine("Ex with GetOccurrence: " & ex.Message) 
        End Try 
    
    End If 
    

    Note that I am a C# developer, so there may well be syntax errors in the above as it’s an amalgamation of the OP’s code and my code converted from C#, and has not been passed through a compiler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get a custom Value from the Custom Field that
I have been trying to get the latest version of phpmailer from here: http://sourceforge.net/projects/phpmailer/files/
I have been trying to get a jquery ajax function to return data from
I have been trying to get Comment action approved from Facebook, The action requires
I have been trying to get a number from a html string, but I
I have been trying to get all rows from the SQLite database. But I
I have been trying to get my Arduino/Eclipse environment setup. For some reason I
I have been trying to get a handle on using MVC 4.0 with EF
I have been trying to get Twitter Bootstrap btn-group with dropdown to work for
I have been trying to get tsung to connect to a box I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.