A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

SaveAs() sometimes loses userProperty!



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 20th 06, 04:19 PM posted to microsoft.public.developer.outlook.addins,microsoft.public.outlook.program_addins,microsoft.public.outlook.program_vba
PuppetMaster
external usenet poster
 
Posts: 4
Default SaveAs() sometimes loses userProperty!

I am creating a VB COM addin for Outlook 2002 and have come up against
the following problem. Sometimes when I create a custom UserProperty
for a mailItem, when I then do a SaveAs() on this item, the
UserProperty disappears.

It seems that the first time I run the code below, it works fine, but
if I run it a second time, it fails! Also, if make a selection of
emails and loop round this code for each one of them, some of the mails
will have the UserProperty in the SaveAs() item, and some won't?!

Can anyone else replicate this problem, or know why this may be
happening?

--------------------------------------
Dim userprop As UserProperty
Set userprop = m4addin.itemObj.UserProperties.Add("archiveTo", olText,
True)
userprop.Value = "C:\temp"
m4addin.itemObj.Save
MsgBox m4addin.itemObj.UserProperties("archiveTo").Value '=OK
Call m4addin.itemObj.SaveAs(myConfig.HDDq & projectFilename & ".msg")
'At this point the customer property may have disappeared!
Dim foo As MailItem
Set foo = m4addin.oApp.CreateItemFromTemplate(myConfig.HDDq &
projectFilename & ".msg")
MsgBox foo.UserProperties.Count
Set foo = Nothing

  #2  
Old January 23rd 06, 05:42 PM posted to microsoft.public.developer.outlook.addins,microsoft.public.outlook.program_addins,microsoft.public.outlook.program_vba
Dave Kane [MVP - Outlook]
external usenet poster
 
Posts: 33
Default SaveAs() sometimes loses userProperty!

CreateItemFromTemplate takes an OFT file as its argument. Try

Call m4addin.itemObj.SaveAs(myConfig.HDDq & projectFilename &
".oft",olTemplate)
and
Set foo = m4addin.oApp.CreateItemFromTemplate(myConfig.HDDq &
projectFilename & ".oft")


"PuppetMaster" wrote in message
oups.com...
I am creating a VB COM addin for Outlook 2002 and have come up against
the following problem. Sometimes when I create a custom UserProperty
for a mailItem, when I then do a SaveAs() on this item, the
UserProperty disappears.

It seems that the first time I run the code below, it works fine, but
if I run it a second time, it fails! Also, if make a selection of
emails and loop round this code for each one of them, some of the mails
will have the UserProperty in the SaveAs() item, and some won't?!

Can anyone else replicate this problem, or know why this may be
happening?

--------------------------------------
Dim userprop As UserProperty
Set userprop = m4addin.itemObj.UserProperties.Add("archiveTo", olText,
True)
userprop.Value = "C:\temp"
m4addin.itemObj.Save
MsgBox m4addin.itemObj.UserProperties("archiveTo").Value '=OK
Call m4addin.itemObj.SaveAs(myConfig.HDDq & projectFilename & ".msg")
'At this point the customer property may have disappeared!
Dim foo As MailItem
Set foo = m4addin.oApp.CreateItemFromTemplate(myConfig.HDDq &
projectFilename & ".msg")
MsgBox foo.UserProperties.Count
Set foo = Nothing



  #3  
Old January 23rd 06, 05:43 PM posted to microsoft.public.developer.outlook.addins,microsoft.public.outlook.program_addins,microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default SaveAs() sometimes loses userProperty!

Actually, it can also take an .msg file, as well as an .oft file, but it would be worth seeing if an .oft file works better in this scenario.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Dave Kane [MVP - Outlook]" wrote in message ...
CreateItemFromTemplate takes an OFT file as its argument. Try

Call m4addin.itemObj.SaveAs(myConfig.HDDq & projectFilename &
".oft",olTemplate)
and
Set foo = m4addin.oApp.CreateItemFromTemplate(myConfig.HDDq &
projectFilename & ".oft")


"PuppetMaster" wrote in message
oups.com...
I am creating a VB COM addin for Outlook 2002 and have come up against
the following problem. Sometimes when I create a custom UserProperty
for a mailItem, when I then do a SaveAs() on this item, the
UserProperty disappears.

It seems that the first time I run the code below, it works fine, but
if I run it a second time, it fails! Also, if make a selection of
emails and loop round this code for each one of them, some of the mails
will have the UserProperty in the SaveAs() item, and some won't?!

Can anyone else replicate this problem, or know why this may be
happening?

--------------------------------------
Dim userprop As UserProperty
Set userprop = m4addin.itemObj.UserProperties.Add("archiveTo", olText,
True)
userprop.Value = "C:\temp"
m4addin.itemObj.Save
MsgBox m4addin.itemObj.UserProperties("archiveTo").Value '=OK
Call m4addin.itemObj.SaveAs(myConfig.HDDq & projectFilename & ".msg")
'At this point the customer property may have disappeared!
Dim foo As MailItem
Set foo = m4addin.oApp.CreateItemFromTemplate(myConfig.HDDq &
projectFilename & ".msg")
MsgBox foo.UserProperties.Count
Set foo = Nothing



  #4  
Old January 24th 06, 10:49 AM posted to microsoft.public.developer.outlook.addins,microsoft.public.outlook.program_addins,microsoft.public.outlook.program_vba
PuppetMaster
external usenet poster
 
Posts: 4
Default 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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Saveas web page shows Appointment and Event Details Robert Grimes Outlook - Calandaring 0 January 30th 06 02:09 PM


All times are GMT +1. The time now is 11:08 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.