Solved

Unable to access properties of AppointmentItem using VB6

Posted on 2008-06-25
7
859 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
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:GHCS_Mark
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

Author Comment

by:Chris Raisin
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 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…
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…

728 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

12 Experts available now in Live!

Get 1:1 Help Now