Outlook Reccurring Appointments

G

Guest

Hi all.

I am writiing a simple application that grabs any appointments and then pages me about 15 minutes before my appointment. (i'm to cheap to buy a PDA) I have everything I need except working code that get's the proper appointments for the day.

I am trying to user VB.Net and have seen ALL of the examples on MSDN but I am still having problems.

Every 15 minutes I want to check the appointments, but when I check them and apply a Restrict on the items it returns 2147483647 items. I'm assuming that's all the days that are available in Outlook.......not really what I am looking for. It seems that my Restrict is not working properly. I have moved it around into different areas and tried the Find method too.

I am using Outlook 2002 and VB.Net to try and do this.

Here is my code. I've tried way too many ideas to give up but alot frustrated. Any assistance would be greatly appreciated.


Dim oAppt As Outlook.AppointmentItem
Dim sSearch As String
Dim oNS As Outlook.NameSpace
Dim oApp As Outlook.Application
Dim oCalendar As Outlook.MAPIFolder
Dim oItems As Outlook.Items
Dim oRestrictedItems As Outlook.Items
Dim AlertTime As Date
Dim i As Integer

'TODO change the 15 minutes to a parameter in the form
'AlertTime = Format(DateAdd("n", 15, Now), "hh:mm:ss")

' Create Outlook application.
oApp = New Outlook.Application

' Get NameSpace and Logon.
oNS = oApp.GetNamespace("mapi")
oNS.Logon("Profile", "Password", False, True) ' TODO:

' Get Appointments collection from the Calendar folder.
oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)

oItems = oCalendar.Items

' Use Find method
sSearch = "[Start] >= '07/06/2004 12:01 AM' and [Start] <= '07/06/2004 11:59 PM'"
Console.WriteLine(sSearch)

oItems = oItems.Restrict(sSearch)
oItems.Sort("[Start]")
oItems.IncludeRecurrences = True

For i = 1 To oItems.Count

oAppt = oItems(i)

'If AlertTime >= CDate(Format(oAppt.Start, "hh:mm:ss")) And AlertTime < oAppt.End Then
Console.WriteLine("The following apppoitment is found:")

Console.WriteLine(oAppt.Subject)
Console.WriteLine(oAppt.Start)
Console.WriteLine(oAppt.Duration)

Next

' Log off.
oNS.Logoff()

' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oAppt = Nothing
 
K

Ken Slovak - [MVP - Outlook]

Open ended recurring appointments (no limit to number or ending date) will
return that number you see. That's the way it works. In cases like that you
are best off not using IncludeRecurrences and getting the master appointment
and from there figuring out what is the most current one in the series using
the RecurrencePattern.

Take a look at the list of Outlook development KB articles and the articles
on .NET development for Outlook from the Resources page at www.microeye.com.
There are a number of KB's that refer to handling recurring appointments and
the VSNet stuff is the best set of references for .NET development for
Outlook.




Billy said:
Hi all.

I am writiing a simple application that grabs any appointments and then
pages me about 15 minutes before my appointment. (i'm to cheap to buy a PDA)
I have everything I need except working code that get's the proper
appointments for the day.
I am trying to user VB.Net and have seen ALL of the examples on MSDN but I am still having problems.

Every 15 minutes I want to check the appointments, but when I check them
and apply a Restrict on the items it returns 2147483647 items. I'm assuming
that's all the days that are available in Outlook.......not really what I am
looking for. It seems that my Restrict is not working properly. I have moved
it around into different areas and tried the Find method too.
I am using Outlook 2002 and VB.Net to try and do this.

Here is my code. I've tried way too many ideas to give up but alot
frustrated. Any assistance would be greatly appreciated.
Dim oAppt As Outlook.AppointmentItem
Dim sSearch As String
Dim oNS As Outlook.NameSpace
Dim oApp As Outlook.Application
Dim oCalendar As Outlook.MAPIFolder
Dim oItems As Outlook.Items
Dim oRestrictedItems As Outlook.Items
Dim AlertTime As Date
Dim i As Integer

'TODO change the 15 minutes to a parameter in the form
'AlertTime = Format(DateAdd("n", 15, Now), "hh:mm:ss")

' Create Outlook application.
oApp = New Outlook.Application

' Get NameSpace and Logon.
oNS = oApp.GetNamespace("mapi")
oNS.Logon("Profile", "Password", False, True) ' TODO:

' Get Appointments collection from the Calendar folder.
oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)

oItems = oCalendar.Items

' Use Find method
sSearch = "[Start] >= '07/06/2004 12:01 AM' and [Start] <= '07/06/2004 11:59 PM'"
Console.WriteLine(sSearch)

oItems = oItems.Restrict(sSearch)
oItems.Sort("[Start]")
oItems.IncludeRecurrences = True

For i = 1 To oItems.Count

oAppt = oItems(i)

'If AlertTime >= CDate(Format(oAppt.Start, "hh:mm:ss")) And AlertTime < oAppt.End Then
Console.WriteLine("The following apppoitment is found:")

Console.WriteLine(oAppt.Subject)
Console.WriteLine(oAppt.Start)
Console.WriteLine(oAppt.Duration)

Next

' Log off.
oNS.Logoff()

' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oAppt = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top