Solved

Unable to access properties of AppointmentItem using VB6

Posted on 2008-06-25
7
860 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 73
VB6 - Convert HH:MM into Decimal 8 54
IF ELSE Statement in Excel Macro VBA 16 62
VBA: copy range dynamically based on config sheet v2 3 31
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 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