B
Billy
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
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