Solved

Unable to access properties of AppointmentItem using VB6

Posted on 2008-06-25
7
862 Views
Last Modified: 2012-06-22
I need help urgently with a problem I am having in trying to access data in the Outlook calendar on my PC.

I am writing code which will eventually write out the data found in various appointemnts stored in the Outlook calendar to a CSV file.

While writing the code I encountered erros in obtaining values hheld in certain properties.

As an example, when trying to access the "Body" and "Categories" property of the AppointmentItem object an error "Runtime error 287: Application defined or object defined error" occurs.

I am not sure whether it is because an item might have no value in a certain property being "inspected" or not. I tried "NOT IsNull(xxxxxxxx)" but that still gave the same error.

In the code attached I am using the MsgBox dialogue simply to test for access to the properties.

I need to see values in each of the follwing properties:  START   SUBJECT  CATEGORIES   BODY

Any help would be greatly appreciated.
Sub GetCalendarItems()
    Dim myOLApp As Outlook.Application
    Dim myNameSpace As Outlook.NameSpace
    Dim myAppointments As Outlook.Items
    Dim myItems As Outlook.Items
    Dim MyItem As Object
    
    Set myOLApp = CreateObject("Outlook.Application")
    Set myNameSpace = myOLApp.GetNamespace("MAPI")
    Set myAppointments = myNameSpace.GetDefaultFolder(olFolderCalendar).Items
    Set myItems = myAppointments.Restrict("[start] >= '01/06/2007'")
    myItems.Sort ("[start]")
    For Each MyItem In myItems
      MsgBox "Date: " + format(MyItem.Start,"dd/mm/yy")
      MsgBox "Subject: " + MyItem.Subject
      MsgBox "Categories: " + MyItem.Categories
      MsgBox "Body: " + MyItem.Body
    Next
    Set myOLApp = Nothing
    Set myNameSpace = Nothing
    Set myAppointments = Nothing
    Set myItems = Nothing
End sub

Open in new window

0
Comment
Question by:Chris Raisin
[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
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:GHCS_Mark
ID: 21870427
Try checking using Is Nothing rather than IsNull().  Items like Categories are arrays and may contain nothing if they have never been populated.

The only other thing to check is what level your security is set to with Outlook.  By default, 2002 and above pop up the annoying security dialogues by default if you attempt to run this kind of script.  If you are seeing no dialog then it may be that it's automatically set to prevent access to properties like .Body.
If Not MyItem.Categories Is Nothing
    MsgBox "We have categories"
Else
    MsgBox "We have no categories"
End If

Open in new window

0
 
LVL 13

Author Comment

by:Chris Raisin
ID: 21876472
Sorry, the same error occurs as soon as I attempt to reference "MyItem.Categories" using your code.
0
 
LVL 3

Expert Comment

by:GHCS_Mark
ID: 21894660
That seems strange.  Check what level you have your Macro security set at and also try fully disabling any anti-virus software that you might have.  It could be interfering thinking there's a harvest attack going on....

I tried your code and it worked perfectly.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 13

Author Comment

by:Chris Raisin
ID: 21896049
I actually don't want to have to adjust the security level, since people using my program will not want that.

I have found the solution to it all by using the Outlook "Redemption" object which by-passes the security patch put in place by Microsoft and also allows the normally "hidden" properties of Outllok object to be seen by code.

It is available (in both a free developers personal version and also as a commercial version when used with distributed applications (which is what I will be doing) through:
                   http://www.bestcode.com/html/outlook_redemption.html

Accordingly this is the best solution to my problem and I am withdrawing the question from "Active" status to "Solved" (or whatever it is called).  :-)

Thanks for your help anyway....

Cheers
Chris
0
 
LVL 3

Expert Comment

by:GHCS_Mark
ID: 21897991
Yes, redemption makes use of Extended MAPI and hence bypasses the whole security model.
0
 
LVL 13

Accepted Solution

by:
Chris Raisin earned 0 total points
ID: 21919830
Thankyou moderator. It seemes a much better way of cleaning things up!   :-)

As I said,

I actually don't want to have to adjust the security level of Outlook, since people using my program will not want that.

I have found the solution to it all by using the Outlook "Redemption" object which by-passes the security patch put in place by Microsoft and also allows the normally "hidden" properties of Outllok object to be seen by code.

It is available (in both a free developers personal version and also as a commercial version when used with distributed applications (which is what I will be doing) through:
                   http://www.bestcode.com/html/outlook_redemption.html

Accordingly this is the best solution to my problem and I am withdrawing the question from "Active" status to "Solved" (or whatever it is called).  :-)

Thanks for your help everyone!....

Cheers
Chris
0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we 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 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…

726 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