Solved

Delete late bound Outlook AppointmentItem fails

Posted on 2004-03-22
4
561 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…

763 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