That loop of yours doesn't save anything, it just overwrites oContact and
myEntryID each pass through the loop. Is that just for testing purposes?
I'm sort of leery about using ReleaseComObject in loops like that unless I
need to. I've found it can destroy any reference to underlying objects, not
just the referenced object. For example, I have an Inspector handler with a
mail item. I also reference the mail item elsewhere. If I call
ReleaseComObject on the item in the Inspector handler it causes any
reference to the mail item elsewhere to fire an exception.
I'd probably first try setting the oContact object to Nothing instead of
calling ReleaseComObject.
I see nothing in the code you show that would cause the problem you cite, is
that the actual code? How are you moving the items, is it using the UI or
using code? Don't forget that if you are doing it in the UI you might be
firing the Explorer.FolderSwitch event on that new folder object. I'd
probably be using BeforeFolderSwitch for whatever needed to be done for a
new folder view and then using Explorer.SelectionChange to handle items in
the Selection.
Also, don't assume that you will always have an ActiveExplorer object.
Outlook can be started using automation with no Explorers. Either use
Application.Explorers.Item(1) after checking Application.Explorers.Count or
wrap your use of ActiveExplorer in a Try...Catch block.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm
"ck" wrote in message
...
Hi Ken,
I manage to find the source of the problem. In my function
oExplorer_FolderSwitch(), i assign contact entry id to a variable called
myEntryID.
Everything work fine until I started to move one of my contact (Contact A)
from one folder to another folder. I am able to move Contact A to the
another
folder on the first 2 time. After that, I am not able to move it anymore.
When i click on Contact A, the contact screen pop up. If i tried to edit
the
name, company or any other contact information and save my changes, it
will
prompt the following message:
- The item cannot be saved because it was changed by another user or in
another window. Do you want to make a copy in the default folder for the
item?
The strange thing is if i commented out the line:
myEntryID = oContact.EntryID
then it will work fine. I tried to used Marshal.ReleaseComObject to
release
the oContact object but i still get the same problem.
It is anything wrong with my Outlook or it is just my code?
Below is the code for my add-in
My code
----------
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
oExplorer = Me.Application.ActiveExplorer
End Sub
Private Sub oExplorer_FolderSwitch() Handles oExplorer.FolderSwitch
Dim oContact As Object
Dim itemIndex As Integer = 1
Dim myEntryID As String = ""
If oExplorer.Selection.Count 0 Then
For itemIndex = 1 To oExplorer.Selection.Count
oContact = oExplorer.Selection.Item(itemIndex)
If (TypeOf oContact Is Outlook.ContactItem) Then
myEntryID = oContact.EntryID
End If
System.Runtime.InteropServices.Marshal.ReleaseComO bject(oContact)
Next
End If
End Sub
Thanks in advance....