?
Solved

Delete late bound Outlook AppointmentItem fails

Posted on 2004-03-22
4
Medium Priority
?
573 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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