Solved

VB.NET Reading Outlook Data From Calendar

Posted on 2007-04-03
3
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

687 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