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}
 
caiodopAsked:
Who is Participating?
 
ttmacConnect With a Mentor Commented:
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
 
sunray_2003Commented:
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
 
caiodopAuthor Commented:
Version: Outlook 11 (2003) - fully updated with SP1

I'm not using word editor.
0
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
sunray_2003Commented:
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
 
caiodopAuthor Commented:
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
 
sunray_2003Commented:
caiodop,

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

SR
0
 
caiodopAuthor Commented:
OK SR, I wait for your help!
0
 
sunray_2003Commented:
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
 
caiodopAuthor Commented:
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
 
sunray_2003Commented:
11 pm ? which location are you in .. somewhere in canada or atlantic ocean..
0
 
caiodopAuthor Commented:
Brazil... was this the best channel to place my question? I post another at Programming > Windows Application, but without answers until now...
0
 
sunray_2003Commented:
Ok.  This is the perfect place to post this question..  Please wait till some other experts well versed in coding come here..
0
 
caiodopAuthor Commented:
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
 
stefriCommented:
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
 
will_scarlet7Commented:
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
 
caiodopAuthor Commented:
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
 
ttmacCommented:
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
 
caiodopAuthor Commented:
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
 
caiodopAuthor Commented:
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
All Courses

From novice to tech pro — start learning today.