[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delete late bound Outlook AppointmentItem fails

Posted on 2004-03-22
4
Medium Priority
?
577 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
3 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 1500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
Suggested Courses
Course of the Month20 days, 14 hours left to enroll

810 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