SaveAs() sometimes loses userProperty!
Thank you for the suggestions, however a definite specification for
this application is that the messages are saved in .msg format. To
satisfy my curiosity I tried saving as an .oft anyway, but it did not
seem to make any difference.
My reasons for wanting to delete the userProperty were mainly due to
the Items.Find function, where I want to filter the items returned
based on whether this field exists or not. From my experience, I have
found that: -
1. When adding a custom field, a kind of "index" is created by Outlook
which enables the ability to use items.find() on that field. However,
this index is only per folder, so if this message item is moved to
another folder, the find function will not work. To resolve this,
either the user needs to manually add the field to their custom view,
or a dummy custom-field add must be repeated for each folder where the
search filter is required to force creation of this index.
2. This "index" mentioned above is automatically created and updated on
item.customProperty.add. No item.save is necessary since the actually
object structure is being changed.
3. When deleting a custom property, the "index" is not actually updated
until an item.save is performed as well! This can be seen by putting
the customProperty field into the folder view and watching the value
change (or not). However, as given in the code in my OP, when
performing the following commands below for the second time on the same
mail item this somehow corrupts the "saveAs" copy and the
customProperty is no longer there! This happens even if I drop the item
after saveAs() and re-reference it from Outlook by its item.EntryID.
item.saveAs()
item.customProperty.delete
item.save
4. To get around this problem, I have simply removed the
item.customProperty.delete and just altered the value of it to "". Then
changed the find filter to
collection.Find("[archiveTo] '' and [archiveTo] nothing ")
Does this whole problem look like an Outlook bug?
-------------------------
'Work around code
Dim userprop As UserProperty
Set userprop = m4addin.itemObj.userproperty.add "archiveTo", olText,
True
userprop.value = archiveLocation
Call m4addin.itemObj.SaveAs(myConfig.HDDq & projectFilename & ".msg")
m4addin.itemObj.UserProperties("archiveTo").Value = ""
m4addin.itemObj.Save
'Checking for customProperty existance in saveAs copy - which should
work now
Dim foo As MailItem
Set foo = m4addin.oApp.CreateItemFromTemplate(myConfig.HDDq &
projectFilename & ".msg")
MsgBox foo.UserProperties.Count
Set foo = Nothing
|