Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2006

Tip: Looking for answers? Try searching our database.

How Can I Flush Outlook Cache?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tadwick - 23 Sep 2006 07:45 GMT
I'm finding that retrieving appointments from the same recipient over and
over is preventing IncludeRecurrences from working properly.  Instead of
individual occurences I keep getting the master.  I've confirmed this by
retrieving appointments from a recipient that hasn't been queried for a while
and I get the individual occurrences.  This only happens in code - when I
view the recipient's calendar the recurring appointments show as expected.  I
am sorting items and setting IncludeRecurrences = True etc so this behaviour
is quite frustrating.

Is this a phenomenon that has been noted elsewhere?  I have only found an
archived post from this newsgroup back in 1994 where Ken Slovak alluded to
strange behaviour all these lines.

see http://www.pcreview.co.uk/forums/thread-1838616.php

Can I solve this by flushing the cache and, if so, how do I do this and how
often do you think I need to do this?

Thanks, Tad
Ken Slovak - [MVP - Outlook] - 25 Sep 2006 22:38 GMT
The 2 KB articles that come to mind about recurring appointments and
retrieving them are http://support.microsoft.com/?kbid=230120 and
http://support.microsoft.com/?kbid=201101.

Does the information in those articles help at all, and does the sample VBA
code from those articles run correctly in your situation?

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> I'm finding that retrieving appointments from the same recipient over and
> over is preventing IncludeRecurrences from working properly.  Instead of
[quoted text clipped - 19 lines]
>
> Thanks, Tad
Tadwick - 27 Sep 2006 06:01 GMT
Hi Ken,

Thanks for the reply.  My problem was defining the appointments in VBA as
Outlook.Appointment instead of object.  That fixed the issue in VBA.  
However, the problem that caused this is that I'm trying to convert my VBA
code to C# and I was getting mixed up with how appointment items are defined
in the two languages.  There is another article
(http://support.microsoft.com/?kbid=310265) that discusses C# and recurrences
but I'm still getting the master appt for recurring appointments.  This only
happens to other users' folder, not my own.  My code is below.  Have you
tried this in dot net 2.0?

Thanks, Tad

public void GetAppointments(String recipient, String entryid)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");

//create recipient
Outlook.Recipient oRcp = oNS.CreateRecipient(recipient);

//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
   {
       Outlook.Items oItms = (Outlook.Items)oFdr.Items;

       strFilter = "([End] > \'September 1, 2006 12:00 AM\' AND [Start] <=
\'March 1, 2007 12:00 AM\')";

       Outlook.Items oApps = oItms.Restrict(strFilter);
       oApps.Sort("[Start]",false);
       oApps.IncludeRecurrences = true;//blnIncludeRecurrences;

       Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oApps.GetFirst();

       while (oAppt != null)
       {
           MessageBox.Show("Subject = " + oAppt.Subject + " Start = " +
oAppt.Start.ToString("MMM dd, yyyy HH:mm"));
           oAppt = (Outlook.AppointmentItem)oApps.GetNext();
       }
   }
}

> The 2 KB articles that come to mind about recurring appointments and
> retrieving them are http://support.microsoft.com/?kbid=230120 and
[quoted text clipped - 26 lines]
> >
> > Thanks, Tad
Ken Slovak - [MVP - Outlook] - 27 Sep 2006 17:36 GMT
Do you have sufficient permissions for accessing that mailbox and its
Calendar folder?

I did a quickie console app using C# and VS2005, Framework 2.0 running on
Outlook 2007.

I hard coded the mailbox recipient and since that Outlook setup has multiple
profiles I had to select an Exchange profile on startup. Other than that it
ran seamlessly and without errors and displayed one at a time all the
appointments.

I created 1 recurring appointment in my sales mailbox, but the principle
should apply even if the folder has many different appointments, mixing
recurring and non-recurring.

The Outlook profile used was my dog's profile against his mailbox on my
Exchange server, so Outlook was logged in as my dog. That profile was able
to access my sales mailbox, but my dog has permissions on that mailbox (he's
my sales manager).

Here's the code I used (appropriate references were set of course):

using System;
using System.Collections.Generic;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;

namespace ConsoleApplication1
{
   public partial class Program
   {
       static void Main(string[] args)
       {
           bool Foobar = false;
           Foobar = GetAppointments();
       }

    private static bool GetAppointments()
    {

       Outlook.Application oApp = new Outlook.Application();
       Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
       Outlook.AppointmentItem oAppt = null;
       int intFoo = 0;

       //create recipient
       Outlook.Recipient oRcp =
oNS.CreateRecipient("sales@slovaktech.com");

       //Get calendar info (appointments)
       Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
       if (oFdr != null)
       {
           Outlook.Items oItms = (Outlook.Items)oFdr.Items;
           oItms.IncludeRecurrences = true;

           string strFilter = "([End] > \'September 1, 2006 12:00 AM\' AND
[Start] <= \'March 1, 2007 12:00 AM\')";

           Outlook.Items oApps = oItms.Restrict(strFilter);
           oApps.Sort("[Start]", false);
           oApps.IncludeRecurrences = true; //blnIncludeRecurrences;

           try
           {
               oAppt = (Outlook.AppointmentItem)oApps.GetFirst();
               intFoo = (int)oAppt.Class;
           }
           catch
           {
               intFoo = 0;
           }

           if (intFoo == 26)
           {
               while (oAppt != null)
               {
                   System.Windows.Forms.MessageBox.Show("Subject = " +
oAppt.Subject + " Start = " +
                       oAppt.Start.ToString("MMM dd, yyyy HH:mm"));

                   oAppt = (Outlook.AppointmentItem)oApps.GetNext();
               }
               return true;
           }
           else
           {
               return false;
           }
       }
       else
       {
           return false;
       }
   }
 }
}

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Hi Ken,
>
[quoted text clipped - 46 lines]
>    }
> }
Tadwick - 27 Sep 2006 21:26 GMT
Hi Ken,

Thank you for trying to replicate the problem.  I don't know think
permissions are a problem because I get the correct dates when I include
recurrences in VBA.  I used your exact code to create a console app
(referencing OL2003 instead of 2007) and again I get the wrong dates.

Just to clarify, I get an instance of an appointment item for each occurence
but the start date is that of the master not the occurence.  This is what was
happening in VBA when I was declaring items as oAppt to
Outlook.AppointmentItem instead of the correct type (object), which is why I
am wondering if it is related to the class definition in C#.

In your test, was the recurring item open ended or did it have an end date?

Thanks again for working with me on this one.

Tad

> Do you have sufficient permissions for accessing that mailbox and its
> Calendar folder?
[quoted text clipped - 146 lines]
> >    }
> > }
Ken Slovak - [MVP - Outlook] - 27 Sep 2006 22:13 GMT
My recurring appointment had an end date. About 20 occurrences were created.

There could be something with the Outlook 2003 PIA's I suppose. Do you have
any open ended recurring series?

I wonder if there'd be any difference running the code in VB.NET? I'll have
to see tomorrow. I can also fire up a VM with VS2005 and Outlook 2003 on it
tomorrow. I happened to be running a VM with Outlook 2007 on it when I was
writing the console app.

If you notice, I did cast the retrieved oAppt as an AppointmentItem.

Signature

Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm

> Hi Ken,
>
[quoted text clipped - 18 lines]
>
> Tad
Tadwick - 27 Sep 2006 22:58 GMT
Ken,

I can't believe this but I bumped up the permissions on a colleague's
mailbox from reviewer to editor and the actual dates showed up.  How this can
be happening I don't know but I'm going to create a new post to this group
since the issue does seem to be permissions-related.

Simon

> My recurring appointment had an end date. About 20 occurrences were created.
>
[quoted text clipped - 30 lines]
> >
> > Tad
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.