Outlook Appointments and VB.Net

  • Thread starter Thread starter Billy
  • Start date Start date
B

Billy

Hi all. Having some problems writing code for an Outlook Application.
Yea I know who has not written on of these. But still. I'm blind.
I have not been able to find a good reference on how to do this. All
I want to do is look at my appointments and then send myself a page
about 15 minutes before my appointment.

Oh yea. This is VB.Net and I have not been able to find a really good
example for .Net. I found plenty for VB6 but have not for .Net 2003.


So at this point I have 2 problems.

#1 in the for loop it does not recognize that I have re-occuring
appointment even though I have specifically stated to do so. I have
tried loops, while statements I even let my 7 year old guess to try
and help. It finds regular appointments but not re-occuring ones. I
know I'm missing something simple here. I think I have looked at too
many code snippets on MSDN.

#2. Even If I go this code to work, is there any way to turn off the
security stuff for outlook so that I get my page instead of having to
click OK to the "An application is sending an e-mail on outlooks
behalf". With everything I have read on MSDN, Microsoft does not want
to allow this, but I'm sure it's possible. How else would you write a
plug in. I also have this need for work because I have another
program I wrote for load testing that scrapes a URL from a specific
e-mail that has not been read. For an hours test I have to have
someone watch the PC because my Quicktest script (Mercury) does not
look for the warning.

BTW, this is NOT something malicious. I have a legitimate need. I
can't remember all my appointment and I am too cheap to buy a PDA.

Anyway. Here is my code, and any help or references would be greatly
appreciated.

Thanks in advance

' Create Outlook application.
Dim oAppt As Outlook.AppointmentItem

'Dim oAppt As Outlook.MeetingItem
Dim apptCount As Integer
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 myCollection As New Collection

' Create Outlook application.
oApp = New Outlook.Application

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

' Get Appointments collection from the Calendar folder.
oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
oCalendar.Items.Sort("[Start]")
oCalendar.Items.IncludeRecurrences = True
oItems = oCalendar.Items

' Use Find method
sSearch = "[Start] >= '" & Format(Today, "MM/dd/yyyy") & "
12:01 AM' and [Start] <= '" & Format(Today, "MM/dd/yyyy") & " 11:59
PM'"

'The following statement uses the Find method of the Items
collection object to
'return the first appointment whose Start field matches the
criteria:
oItems = oItems.Restrict(sSearch)

Dim i As Integer
Dim cnt As Integer

For i = 1 To oItems.Count
oAppt = oItems.Item(i)
Console.WriteLine("The following apppointment is found:")
Console.WriteLine(oItems.Count & " record found")
Console.WriteLine(oAppt.Subject & " Subject")
Next
 
#1: You need to instantiate an Items object variable in order to use
IncludeRecurrences. Try:

oItems = oCalendar.Items
oItems.Sort("[Start]")
oItems.IncludeRecurrences = True

#2: See http://www.outlookcode.com/d/sec.htm for your options with regard to
the "object model guard" security in Outlook 2000 SP2 and later versions.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Billy said:
Hi all. Having some problems writing code for an Outlook Application.
Yea I know who has not written on of these. But still. I'm blind.
I have not been able to find a good reference on how to do this. All
I want to do is look at my appointments and then send myself a page
about 15 minutes before my appointment.

Oh yea. This is VB.Net and I have not been able to find a really good
example for .Net. I found plenty for VB6 but have not for .Net 2003.


So at this point I have 2 problems.

#1 in the for loop it does not recognize that I have re-occuring
appointment even though I have specifically stated to do so. I have
tried loops, while statements I even let my 7 year old guess to try
and help. It finds regular appointments but not re-occuring ones. I
know I'm missing something simple here. I think I have looked at too
many code snippets on MSDN.

#2. Even If I go this code to work, is there any way to turn off the
security stuff for outlook so that I get my page instead of having to
click OK to the "An application is sending an e-mail on outlooks
behalf". With everything I have read on MSDN, Microsoft does not want
to allow this, but I'm sure it's possible. How else would you write a
plug in. I also have this need for work because I have another
program I wrote for load testing that scrapes a URL from a specific
e-mail that has not been read. For an hours test I have to have
someone watch the PC because my Quicktest script (Mercury) does not
look for the warning.

BTW, this is NOT something malicious. I have a legitimate need. I
can't remember all my appointment and I am too cheap to buy a PDA.

Anyway. Here is my code, and any help or references would be greatly
appreciated.

Thanks in advance

' Create Outlook application.
Dim oAppt As Outlook.AppointmentItem

'Dim oAppt As Outlook.MeetingItem
Dim apptCount As Integer
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 myCollection As New Collection

' Create Outlook application.
oApp = New Outlook.Application

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

' Get Appointments collection from the Calendar folder.
oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar)
oCalendar.Items.Sort("[Start]")
oCalendar.Items.IncludeRecurrences = True
oItems = oCalendar.Items

' Use Find method
sSearch = "[Start] >= '" & Format(Today, "MM/dd/yyyy") & "
12:01 AM' and [Start] <= '" & Format(Today, "MM/dd/yyyy") & " 11:59
PM'"

'The following statement uses the Find method of the Items
collection object to
'return the first appointment whose Start field matches the
criteria:
oItems = oItems.Restrict(sSearch)

Dim i As Integer
Dim cnt As Integer

For i = 1 To oItems.Count
oAppt = oItems.Item(i)
Console.WriteLine("The following apppointment is found:")
Console.WriteLine(oItems.Count & " record found")
Console.WriteLine(oAppt.Subject & " Subject")
Next
 
Back
Top