Solved

VB.NET Reading Outlook Data From Calendar

Posted on 2007-04-03
3
255 Views
Last Modified: 2013-12-25
I am using this code from another solution on this site:

    'In your project include a reference to Microsoft Outlook x.x Object Library
    'where x.x is your version of Outlook
    Dim objApp As Outlook.Application, _
        objNS As Outlook.NameSpace, _
        objCalendar As Outlook.MAPIFolder, _
        objAppointment As Outlook.AppointmentItem
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    'Change OutlookProfileName to the name of your Outlook profile
    objNS.Logon "OutlookProfielName"
    Set objCalendar = objNS.GetDefaultFolder(olFolderCalendar)
   
    'To access each appointment in the calendar do this
    For Each objAppointment In objCalendar.Items
        'Code to do whatever you want to do with each appointment
>      TempVal = (objAppointment.Subject.ToString).ToString
    Next

However I added the part with the >

The problem is if the calendar has no subject, the program crashes.  Can I fix this?
0
Comment
Question by:Crazy_Penguins
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
cavehop earned 500 total points
ID: 18847209
Probably the easiest way is to check if the Subject exists prior to calling the ToString method.
e.g.
If Not objAppointment.Subject Is Nothing
  TempVal = (objAppointment.Subject.ToString).ToString
Else
  TempVal = "(No Subject)"
End If

Hope this helps,
--Lance--
0
 

Author Comment

by:Crazy_Penguins
ID: 18847549
Thanks Lance!
0
 
LVL 4

Expert Comment

by:cavehop
ID: 18850696
Your most welcome. Glad I could help.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now