Link to home
Start Free TrialLog in
Avatar of caiodop
caiodop

asked on

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

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}
 
Avatar of sunray_2003
sunray_2003
Flag of United States of America image

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.

Avatar of caiodop
caiodop

ASKER

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

I'm not using word editor.
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
Avatar of caiodop

ASKER

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
caiodop,

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

SR
Avatar of caiodop

ASKER

OK SR, I wait for your help!
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
Avatar of caiodop

ASKER

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
11 pm ? which location are you in .. somewhere in canada or atlantic ocean..
Avatar of caiodop

ASKER

Brazil... was this the best channel to place my question? I post another at Programming > Windows Application, but without answers until now...
Ok.  This is the perfect place to post this question..  Please wait till some other experts well versed in coding come here..
Avatar of caiodop

ASKER

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
Avatar of 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


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
ASKER CERTIFIED SOLUTION
Avatar of ttmac
ttmac

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of caiodop

ASKER

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
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.
Avatar of caiodop

ASKER

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
Avatar of caiodop

ASKER

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}