Solved

Delete late bound Outlook AppointmentItem fails

Posted on 2004-03-22
4
562 Views
Last Modified: 2008-02-01
I'm trying to delete an Outlook AppointmentItem for which I have the EntryID. Using late binding to avoid referencing a specific verison of Outlook.

Thefollowing code fails on myappt.delete with a 287 (Application defined or object defined error.):

    Dim myAppt As Object 'AppointmentItem 'object
    Dim myNS As Object 'NameSpace 'object
    Dim myAppts As Object 'Items 'object
...
                success = manageOutlookRef 'get a reference to Outlook
                Set myNS = myOlApp.GetNamespace("MAPI")
                Set myAppts = myNS.GetDefaultFolder(9).items '9=olFolderCalendar
             
               
                Set myAppt = myNS.getItemFromID(OutID)
                If Not myAppt Is Nothing Then
                    'delete it and stop
                    myAppt.Delete <<<<<<<FAILS HERE
                    ctDaySked.DeleteAppointment (ctDaySked.AppointSelect)
                    UpdateStatusBar " Outlook Appointment deleted."
               
                End If

I can get the typeName, Class, subject of myAppt, but not its start, end or Outlookversion (?) What's wrong with my code? or whats a surefire way of doing this from VB6 (late bound)?

Thanks!
0
Comment
Question by:thePrisoner
  • 2
4 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 10729407
I tried to duplicate the problem by filling in the code that you omitted from your post (i.e. I took an educated guess at what you left out above).  I wasn't able to get the same error that you descibed but I did run into something that could possibly be related to what you're seeing.  Specifically, when trying to just loop through my appointments and view them in the debugger I discovered that some appointment items wouldn't load.  When the loop hit those records I got a "Run-time error '13'  Type Mismatch"  After some additional testing I found that some items in various containers (e.g. Contacts) produces the same error.  Not sure why although I read a post on another forum suggesting that this is a result of the item having something in it that Outlook can't handle.  I'm guessing that means that a field has an invalid value or isn't filled in, or something of that nature.  On learning that I modified my code to jump over those items and then everything worked fine.  I was able to delete an appointment without incident.  

For whatever it's worth, here's my test code.  I tested this on Outlook 2003.

    Dim oOutlook As Outlook.Application
    Dim oNameSpace As NameSpace
    Dim oFolder As MAPIFolder
    Dim ocalItems As Outlook.Items
    Dim Appointment As Outlook.AppointmentItem
    Dim intItemToDelete As Integer

    Set oOutlook = New Outlook.Application
    Set oNameSpace = oOutlook.GetNamespace("MAPI")
    oNameSpace.Logon
    Set oFolder = oNameSpace.GetDefaultFolder(olFolderCalendar)
    Set ocalItems = oFolder.Items
 
    intItemToDelete = 64     'My test appointment was number 64
   
    Set Appointment = ocalItems.Item(intItemToDelete)
    Appointment.Delete

You didn't mention what version of Outlook you're using so I don't if these will help, but I did find a couple of items that might be of use in solving this problem.

http://support.microsoft.com/?kbid=830902
http://support.microsoft.com/default.aspx?scid=kb;EN-US;287530
0
 

Author Comment

by:thePrisoner
ID: 10729494
Hi BlueDevilFan!

What's this line?: oNameSpace.Logon

the problem is that the exact same code will execute the first time... then fail thereafter. the error is a 287, when certain, basic properties of the item cannot be accessed, like EntryID.

But, thanks for the interest; and let me know here if you have any idea why entryid would suddenly become inaccessable...
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 10731397
Good morning, thePrisoner.

oNameSpace.Logon logs you in to the MAPI system.  The Logon method takes parameters such as ProfileName, ProfilePassword, ShowDialog, NewSession, and a couple of others that aren't terribly important.  According to the CDO documentation logging in is a requirement before you can do anything in the MAPI system.  Here's a link to documentation on the method at Microsoft's MSDN site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_olemsg_logon_method_session.asp

As noted in my explanation of what I tried, I ran into something similar in that I couldn't read certain entries in both the calendar and contacts.  Although I got a different error message than you're seeing I can't help but wonder if the root cause might be the same in both cases.  What version of Outlook is on the PC where you're testing this?  Also, can you post a bit more of your code (i.e. all the salient code in the procedure that's failing) and the test data you're working against?  I'd like to try and duplicate your environment more closely in order to see if I can get the same error you are and help you find a solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now