Delete late bound Outlook AppointmentItem fails

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!
thePrisonerAsked:
Who is Participating?
 
David LeeConnect With a Mentor Commented:
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
 
David LeeCommented:
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
 
thePrisonerAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.