Solved

Outlook add-in error: "The item has been moved or deleted" URGENT

Posted on 2004-10-25
4,155 Views
Last Modified: 2013-01-18
My problem is to work with more than one instance of e-mail (MailItem).
When I try to send a mail item the send method works fine, but when I open two or more e-mails, send one and then send other, the e-mail object (MailItem) doesn't have the properties anymore returning the error message: "The item has been moved or deleted".

When the e-mail is sent, the e-mail object (MailItem) loses all its properties.

{Please do not post emails/websites in signature in questions - ee_ai_construct, cs admin}
 
0
Question by:caiodop
    19 Comments
     
    LVL 49

    Expert Comment

    by:sunray_2003
    What version of outlook ?

    Is your outlook fully updated ?

    Check to see if you have word as the default email editor by going to tools -> options -> mail format
    if you have it ,uncheck that option and use outlook as the email editor and see if that would solve your issue.

    0
     

    Author Comment

    by:caiodop
    Version: Outlook 11 (2003) - fully updated with SP1

    I'm not using word editor.
    0
     
    LVL 49

    Expert Comment

    by:sunray_2003
    caiodop,

    without that add-in , are you able to send multiple emails fine.

    have you tried to remove that add-in and add it back to see if that would help

    Is this the first time you are working on this add-in or it has worked before fine
    0
     

    Author Comment

    by:caiodop
    I built it many times...

    See if is there a problem with the code:

    --CODE BEGIN--
    (...)
    '----------NEW INSPECTOR
    Private Sub m_olInspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles m_olInspectors.NewInspector
            Try
                m_olInspector = CType(Inspector, Outlook.InspectorClass)
                If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
                    'Must cast to MailItemClass due to "ambiguous name" problem
                    m_olMailItem = CType(Inspector.CurrentItem, Outlook.MailItemClass)
                ElseIf TypeOf Inspector.CurrentItem Is Outlook.PostItem Then
                    m_olPostItem = CType(Inspector.CurrentItem, Outlook.PostItem)
                'ANOTHERS TYPE VERIFICATIONS
                (...)
                End If
            Catch ex As Exception
                MsgBox(ex.Message & Chr(13) & "Please, try again." & Chr(13) & Chr(13) & "If this problem persists, contact your system administrator. Code: 0013", MsgBoxStyle.Exclamation, "Outlook")
            End Try
        End Sub

    '----------MAIL OPEN
        Private Sub m_olMailItem_Open(ByRef Cancel As Boolean) Handles m_olMailItem.Open
            Try
                CBBSaveSendOnOff(m_olMailItem, True, True) 'Just make buttons
            Catch ex As Exception
                MsgBox(ex.Message & Chr(13) & _
                "Please, try again." & Chr(13) & Chr(13) & "If this problem persists, contact your system administrator. Code: 0017", MsgBoxStyle.Exclamation, "Outlook")
            End Try
        End Sub

    --CODE END--

    Up to here I have the item opened. When the user clicks on my button...:

    --CODE BEGIN--
    '----------CLICK ON THE CUSTOM SEND BUTTON
        Private Sub CBBSendEmail_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles CBBSendEmail.Click
            Try
                If Not (m_olMailItem Is Nothing) Then
                    BTNSend = True 'JUST FOR A FUTURE VERIFICATION
                    m_olMailItem.Send()
                End If
            Catch ex As Exception
                MsgBox(ex.Message & Chr(13) & _
                "Please, try again." & Chr(13) & Chr(13) & "If this problem persists, contact your system administrator. Code: 0024", MsgBoxStyle.Exclamation, "Outlook")
            End Try
        End Sub
    --CODE END--

    This m_olMailItem has all the properties of the e-mail. When an e-mail is sent, it loses its properties. So when is opened more than one e-mail and one of them is sent, the other one doesn't have the necessary properties to send the e-mail.

    Did you understand my problem?

    Caio
    0
     
    LVL 49

    Expert Comment

    by:sunray_2003
    caiodop,

    Sorry , I am not good at this.. I shall try to get help for you here.. Hang on

    SR
    0
     

    Author Comment

    by:caiodop
    OK SR, I wait for your help!
    0
     
    LVL 49

    Expert Comment

    by:sunray_2003
    caiodop,

    Have asked the PE for this TA to contact some experts who are good at coding in outlook. Hope they would be here soon

    SR
    0
     

    Author Comment

    by:caiodop
    OK SR...

    I'll be trying a solution... It's late here (11pm at office!).... but I need to solve it!

    Thanks... I'm waiting for any help!

    Caio
    0
     
    LVL 49

    Expert Comment

    by:sunray_2003
    11 pm ? which location are you in .. somewhere in canada or atlantic ocean..
    0
     

    Author Comment

    by:caiodop
    Brazil... was this the best channel to place my question? I post another at Programming > Windows Application, but without answers until now...
    0
     
    LVL 49

    Expert Comment

    by:sunray_2003
    Ok.  This is the perfect place to post this question..  Please wait till some other experts well versed in coding come here..
    0
     

    Author Comment

    by:caiodop
    I'll go home now... sleep to wake up early tomorrow and solve this problem... if someone help me, please, post here or send me an email {2 adresses removed - ee_ai_construct, cs admin (see http:help.jsp#hi99 for details)}

    I'll be back in about 8 hours...

    I appreciate any help.

    Caio
    0
     
    LVL 13

    Expert Comment

    by:stefri
    caiodop,
    I do not know the language you are using even if it looks like VB but:
    how is declared m_olMailItem? Seems to be global variable which is initialized in m_olInspectors_NewInspector.
    If you have more than one item opened, it will be replaced by the new value?
    The custom button belongs to the mail you are sending? Cant you get a handle on the mail item itself as the sub does not reference it.
    Stefri


    0
     
    LVL 15

    Expert Comment

    by:will_scarlet7
    Hi All,
    (caiodop, I'm not one of the experts called in, but rather a passer by with a comment)
        I also am not familiar with the language (am guessing it is Java or a similar scripting language), but what about setting a hard limit on how many emails you can work with? Set up multiple MailItem Objects and in the send sequence each one is cleared, so when you try to open a new one it looks to si if one of the Objects is empty first and if so assigns the MailItem to that object, if not pops up a message to the user that they have reached the limit of open emails.
        I realize this is rather limiting, to hard code a limit into your app for the number of open MailItems. Like I said I am not one of the coding experts.

    Sam
    0
     
    LVL 1

    Accepted Solution

    by:
    caiodop,

    It sounds as if the mail item you are trying to send is no longer an active mailitem.  This would be true if your user opens an email and returns to the outlook window and opens a second email.  After the send event has taken place, windows returns to the previous window that was active, and in this case it returns to the Outlook Window.

    In order to be able to send the first email you will firstly have to make it current.  In the windows environment this would be by clicking on the mailitem button on the task bar or by ALT-Tabbing.

    To implement this in code, you will need to use the Active Inspector method.  This returns the topmost Inspector object on the desktop. If no inspector is active, returns Nothing. Use this method to access the Inspector object that the user is most likely to be viewing.

    A sample of its use in the VBA environment (from the VBA help) is: -

    Set myOlApp = CreateObject("Outlook.Application")
    Set myInspector = myOlApp.ActiveInspector
    MsgBox "The active item is " & myInspector.CurrentItem.Subject

    Tom.

    0
     

    Author Comment

    by:caiodop
    I think that everybody understood the problem.

    About Sam's idea, I had been thought before and it would work fine, but I want to try something else to do not limit the users or fill a large memory space, I'm going to make it just on a B plan :)

    Using Stefri's idea and Tom's VBA code it works fine, but I'm building using VB.NET in Visual Studio .NET 2003, so I need something to integrate the VB.NET to the VBA code. Maybe VSTO?

    I have two objects that are not working fine:
    1) The inspetor: the inspector object just get the first e-mail
    2) The MailItem: after sending, it loses the properties, so when I try to send another I get the error message: "The item has been moved or deleted".

    Any ideas about what is the best thing to do?

    Thanks for the help... in our area we really need a strong and cooperative community to work together!
    Caio
    0
     
    LVL 1

    Expert Comment

    by:ttmac
    caiodop,

    When you send the mail item, is the instance of the inspector remaining open even though the mail item has been sent?

    If this is the case you might appear to have an inspector set as the current inspector eventhough it does not contain a mail item.  

    I have no experience of VB.Net  so I cannot offer you any advice in that regard, however if you are making reference to the outlook object in your references and you are able to create and manipulate Outlook objects there should be no reason why you cannot integrate the VBA example above into your application.  VBA is simply a cut down version of VB.  

    A possible alternative that you might consider is to loop through all the inspectors that are open and test if they possess the properties that you require, then set one of them as the active or current inspector.

    Tom.
    0
     

    Author Comment

    by:caiodop
    Tom,

    I've tryed many times to get the current item (Inspector), but I anything worked until now...

    I have an idea... I'm going to try and tell you if it worked.

    Caio
    0
     

    Author Comment

    by:caiodop
    I did it and it is working well using Tom's idea...!

    I'd like to thank everyone here!

    Below is the finally working code:

    --CODE BEGIN--

        Private Sub CBBSendEmail_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles CBBSendEmail.Click
            Try
                m_olInspector = CType(m_olApp.ActiveInspector, Outlook.InspectorClass)
                getItem(m_olInspector)
                If Not (m_olMailItem Is Nothing) Then
                    BTNSend = True
                    m_olMailItem.Send()
                    m_olInspector = CType(m_olApp.ActiveInspector, Outlook.InspectorClass)
                    getItem(m_olInspector)
                End If
                'Wilson: 1.0.1.41 - end
            Catch ex As Exception
                MsgBox(ex.Message & Chr(13) & _
                "Please, try again." & Chr(13) & Chr(13) & "If this problem persists, contact your system administrator. Code: 0024", MsgBoxStyle.Exclamation, "Outlook")
            End Try
        End Sub

        Private Sub getItem(ByVal inspector As Outlook.InspectorClass)
            Try
                If TypeOf inspector.CurrentItem Is Outlook.MailItem Then
                    'Must cast to MailItemClass due to "ambiguous name" problem
                    m_olMailItem = CType(inspector.CurrentItem, Outlook.MailItemClass)
                ElseIf TypeOf inspector.CurrentItem Is Outlook.PostItem Then
                    m_olPostItem = CType(inspector.CurrentItem, Outlook.PostItem)
                ElseIf TypeOf inspector.CurrentItem Is Outlook.AppointmentItem Then
                    m_olAppointmentItem = CType(inspector.CurrentItem, Outlook.AppointmentItem)
                ElseIf TypeOf inspector.CurrentItem Is Outlook.ContactItem Then
                    m_olContactItem = CType(inspector.CurrentItem, Outlook.ContactItem)
                ElseIf TypeOf inspector.CurrentItem Is Outlook.DistListItem Then
                    m_olDistListItem = CType(inspector.CurrentItem, Outlook.DistListItem)
                ElseIf TypeOf inspector.CurrentItem Is Outlook.JournalItem Then
                    m_olJournalItem = CType(inspector.CurrentItem, Outlook.JournalItem)
                ElseIf TypeOf inspector.CurrentItem Is Outlook.TaskItem Then
                    m_olTaskItem = CType(inspector.CurrentItem, Outlook.TaskItem)
                End If
            Catch ex As Exception
                'This try block is just to threat if the last mail is closed and there is no Inspector open
            End Try
        End Sub

    --CODE END--

    Best regards,

    Caio Pereira
    {Please do not post emails/websites in signature in questions - ee_ai_construct, cs admin}
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    884 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

    18 Experts available now in Live!

    Get 1:1 Help Now