cant open custom contact after modifying it

D

David

I have a COM-Addin that goes through all the contacts in the contacts
folders, coverts them to the custom contact form, then modifies some data in
each contact. After this process, if you double click on a contact to open
it nothing happens..no error message, nothing. I know its not the converting
part because I have broken down the process into separate steps. So it has
something to do with modifing the custom data. Basically to modify the data
I just do something like the following

myitem = objFolder.Items.Find("[FullName] = """ & strName & """")
If Not myitem Is Nothing Then
Dim up As Outlook.UserProperty
up = myitem.UserProperties.Item("MyCustomProp")
If Not up Is Nothing Then
up.Value = strResult
End If
up = Nothing
End If

However if I shut down outlook, then open it again, i can open contact items
again. Any ideas?
Thanks

David
 
K

Ken Slovak - [MVP - Outlook]

Try Set up = myitem.UserProperties.Item("MyCustomProp")
and Set up = Nothing. "up" is an object so you have to use Set. Also, save
the item after you change something.
 
S

Sue Mosher [MVP-Outlook]

Are you also setting myItem to Nothing somewhere later in your code?
 
D

David

Yes I am. I though it might be that I forget to save the item after changing
it. So I added myite.save after changing the custom propery, but
myitem.save throws a "Operation aborted." exception.

Sue Mosher said:
Are you also setting myItem to Nothing somewhere later in your code?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



David said:
I have a COM-Addin that goes through all the contacts in the contacts
folders, coverts them to the custom contact form, then modifies some
data
in
each contact. After this process, if you double click on a contact to open
it nothing happens..no error message, nothing. I know its not the converting
part because I have broken down the process into separate steps. So it has
something to do with modifing the custom data. Basically to modify the data
I just do something like the following

myitem = objFolder.Items.Find("[FullName] = """ & strName & """")
If Not myitem Is Nothing Then
Dim up As Outlook.UserProperty
up = myitem.UserProperties.Item("MyCustomProp")
If Not up Is Nothing Then
up.Value = strResult
End If
up = Nothing
End If

However if I shut down outlook, then open it again, i can open contact items
again. Any ideas?
Thanks

David
 
D

David

This is VB.NET (sorry to not mention it). So everytime i enter "set x =
something" .NET removes the "set"

I did add the "myitem.save" but it throws a "operation aborted" exception.
any ideas?


Ken Slovak - said:
Try Set up = myitem.UserProperties.Item("MyCustomProp")
and Set up = Nothing. "up" is an object so you have to use Set. Also, save
the item after you change something.




David said:
I have a COM-Addin that goes through all the contacts in the contacts
folders, coverts them to the custom contact form, then modifies some
data
in
each contact. After this process, if you double click on a contact to open
it nothing happens..no error message, nothing. I know its not the converting
part because I have broken down the process into separate steps. So it has
something to do with modifing the custom data. Basically to modify the data
I just do something like the following

myitem = objFolder.Items.Find("[FullName] = """ & strName & """")
If Not myitem Is Nothing Then
Dim up As Outlook.UserProperty
up = myitem.UserProperties.Item("MyCustomProp")
If Not up Is Nothing Then
up.Value = strResult
End If
up = Nothing
End If

However if I shut down outlook, then open it again, i can open contact items
again. Any ideas?
Thanks

David
 
S

Sue Mosher [MVP-Outlook]

Does this occur when the property exists or when it doesn't exist or in both
cases?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



David said:
Yes I am. I though it might be that I forget to save the item after changing
it. So I added myite.save after changing the custom propery, but
myitem.save throws a "Operation aborted." exception.

Sue Mosher said:
Are you also setting myItem to Nothing somewhere later in your code?

David said:
I have a COM-Addin that goes through all the contacts in the contacts
folders, coverts them to the custom contact form, then modifies some
data
in
each contact. After this process, if you double click on a contact to open
it nothing happens..no error message, nothing. I know its not the converting
part because I have broken down the process into separate steps. So it has
something to do with modifing the custom data. Basically to modify the data
I just do something like the following

myitem = objFolder.Items.Find("[FullName] = """ & strName & """")
If Not myitem Is Nothing Then
Dim up As Outlook.UserProperty
up = myitem.UserProperties.Item("MyCustomProp")
If Not up Is Nothing Then
up.Value = strResult
End If
up = Nothing
End If

However if I shut down outlook, then open it again, i can open contact items
again. Any ideas?
 
K

Ken Slovak - [MVP - Outlook]

Sorry, no idea with VB.NET, I never use it for Outlook coding.
 
D

David

This happens when the property exists.

To be exact, myitem.Save produces
System.Runtime.InteropServices.COMException error, the source is blank and
the message is "Operation Aborted."

It also seems that if I run my program once it works, but if I run it again
(back to back) it produces the error.
But I "fixed" that by checking to see if the new user property value is
different before setting it.

But I still cant open a custom contact item if I run my function 2 times in
a row.

Here is my function if that helps

Private Sub ImportFile(ByVal strFileName As String, ByVal strPhoneResult
As String)
Dim sr As System.IO.StreamReader
Dim myitem As Outlook.ContactItem
Dim strName As String
Dim strPhoneType As String
Dim strPhoneNumber As String
Dim strCurrentName As String
Dim str As String
Dim strArray() As String

Try
If System.IO.File.Exists(strFileName) Then
sr = New System.IO.StreamReader(strFileName)

Do While sr.Peek() >= 0
'read in data
str = sr.ReadLine

If Not str Is Nothing Then
'parse it to its individual components
strArray = str.Split(",".ToCharArray, 3)
strName = strArray(0)
strPhoneType = strArray(1)
strPhoneNumber = strArray(2)

'do you have a new contact or same contact?
If strCurrentName = "" Or strCurrentName <> strName
Or myitem Is Nothing Then
'we have a new contact
If Not myitem Is Nothing Then
'save the old contact information first
If Not myitem.Saved Then
myitem.Save() '<----BLOW UP HERE
End If
myitem = Nothing
End If
'find the contact we are looking for
myitem = objFolder.Items.Find("[FullName] = """
& strName & """")
strCurrentName = strName

'if we never seen this contact before, undate the counter
If IsNewContact(strName) Then
colContacts.Add(strName, strName)
countContacts = countContacts + 1
End If
End If

'so we have a valid contact
If Not myitem Is Nothing Then
'get out custom property to update
Dim up As Outlook.UserProperty
up = myitem.UserProperties.Item(strPhoneType &
"DNC")
If Not up Is Nothing Then
'update the dnc value for that phone number
up.Value = strPhoneResult

countPhone = countPhone + 1
Else
'contact was found, but not the right form
countInvalidContacts = countInvalidContacts
+ 1
End If
up = Nothing
Else
'no contact exists?
countNotFoundContacts = countNotFoundContacts +
1
End If
End If
Loop

'make sure the last contact access is saved
If Not myitem Is Nothing Then
If Not myitem.Saved Then
myitem.Save() <--- OR BLOWS UP HERE
End If
myitem = Nothing
End If

End If

Catch ex As Exception
PopupError(ex, "ImportFile - " + strCurrentName)
Finally
'clean up the reader and other variables
If Not sr Is Nothing Then
sr.Close()
sr = Nothing
End If
myitem = Nothing
System.Threading.Thread.Sleep(1000)
End Try
End Sub
 
S

Simon Smith

This happens when the property exists.

To be exact, myitem.Save produces
System.Runtime.InteropServices.COMException error, the source is blank and
the message is "Operation Aborted."

It also seems that if I run my program once it works, but if I run it again
(back to back) it produces the error.
But I "fixed" that by checking to see if the new user property value is
different before setting it.

But I still cant open a custom contact item if I run my function 2 times in
a row.

Here is my function if that helps

<snip code>

I'm not a Vber and I've not seen this problem, but I've done COM addins
in C# so maybe this'll help.
I can't see in the code where you're creating/assigning myitem, but you're
setting it to nothing towards the end. You should also probably call System.Runtime.InteropServices.Marshal.ReleaseComObject
on it as well otherwise the CCW may not release it in a timely manner (at
least until the GC runs).
I have a utility method like this (C# but I'm sure you'll get the idea)
in a class called ComUtil:
public static void ReleaseComObject(object o) {
try {
if (o != null) {
while (true) {
int i = Marshal.ReleaseComObject(o);
if (i <= 0) {
break;
}
}
}
} catch {}
}

Whenever I want to 'free' an Outlook object I do:

MAPIFolder folder = .....
// use it
ComUtil.ReleaseComObject(folder);
folder = null;


HTH
 
D

David

Thank you for your post.
The object "myitem" is set by the following line

myitem = objFolder.Items.Find("[FullName] = """ & strName & """")

where objFolder is a MAPIFolder type, created somewhere else.

Anyway, I have added the ReleaseComObject function and call on every object
that I create write before setting the object to Nothing (null). But the
problems still don't go away. I still get the "Operation Aborted" when I try
to call myitem.Save and I still can open the contact item after the function
is run.

Any other suggestion?

David
 
S

Simon Smith

Thank you for your post.
The object "myitem" is set by the following line

myitem = objFolder.Items.Find("[FullName] = """ & strName & """")

where objFolder is a MAPIFolder type, created somewhere else.

Anyway, I have added the ReleaseComObject function and call on every object
that I create write before setting the object to Nothing (null). But the
problems still don't go away. I still get the "Operation Aborted" when I try
to call myitem.Save and I still can open the contact item after the function
is run.

Any other suggestion?

David

The first thing I can suggest is checking the Exception object which is
thrown and seeing whether it has an InnerException which might hold more
details.
Also, what type is myitem? Is it just object? If so, try typing it to
what it actually is - Microsoft.Office.Interop.Outlook.ContactItem or whatever.
 
D

David

I checked the InnerException and its Nothing. myitem is declared as type of
Outlook.ContactItem.


Simon Smith said:
Thank you for your post.
The object "myitem" is set by the following line

myitem = objFolder.Items.Find("[FullName] = """ & strName & """")

where objFolder is a MAPIFolder type, created somewhere else.

Anyway, I have added the ReleaseComObject function and call on every object
that I create write before setting the object to Nothing (null). But the
problems still don't go away. I still get the "Operation Aborted" when I try
to call myitem.Save and I still can open the contact item after the function
is run.

Any other suggestion?

David

The first thing I can suggest is checking the Exception object which is
thrown and seeing whether it has an InnerException which might hold more
details.
Also, what type is myitem? Is it just object? If so, try typing it to
what it actually is - Microsoft.Office.Interop.Outlook.ContactItem or whatever.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top