method .CreateItemFromTemplate is incorrect - ol2003 sp2 issue?

  • Thread starter Thread starter Ronald van Aalten
  • Start date Start date
R

Ronald van Aalten

My app (VB6) imports an task from a .msg file with the
..CreateItemFromTemplate statement:

Set moItem = goOutl.CreateItemFromTemplate(msMsgFile, moOlFld)

The param moOlFld is an task outlook.mapifolder and the task should be
imported into this folder. This used to worke fine and now suddenly it
doesn't work anymore. Nothing has been changed in the code and neither has
the code that produces the .msg file. The task is now incorrectly imported
in the default task folder.

What is even worse is that my code sets several named properties (with
Redemption latest version) which also used to work fine but now the named
properties mysteriously disppear without a trace. No errors are raised in
the code and stepping through the code all seams to go well. I can even
retreive a named property in the debug window; seams ok. But when the import
has finished ALL named properties are gone (I use OultookSpy to inspect the
task item).

I installed office 2003 sp2 yesterday. Could that be the cause of this
mysterious problem? Any experiences yet with extended mapi problems after
sp2 installation?

Ronald van Aalten
 
Don't know about the CreateItemFromTemplate problem, but for the
disappearing properties, save the item first (moItem.Save), then add named
properties using Redemption, then try to mark the item as dirty
(moItem.Subject=moItem.Subject would do), then save again.
In the worst case you can reopen the item using MAPIUtils.GetItemFromID and
then set the named props.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
There is a known problem with Post forms and CreateItemFromTemplate and then
publishing a custom form using code. I'm not sure about task forms.
 
Can the file (item) be saved as an OFT file? See if that helps with SP2.
 
Hi Dmitry,

I already tried exactly what you are describing but to no avail.
The problem is related to the fact that I specifiy a folder in the
CreateItemFromTemplate method other then the item's default folder. If I
repeat my tests with a task in the default Tasks folder then there's no
problem, all named properties remain.
Here's a piece of my coding:
Set moItemOther = goOutl.CreateItemFromTemplate(msMsgFile, moOlFld)
' test if the item is imported in the correct folder, if not move it:
If moItemOther.Parent.EntryID <> moOlFld.EntryID Then
moItemOther.Save
moItemOther.Move moOlFld
End If
moItemOther.Save
sTemp = moItemOther.EntryID
Set moItemOther = Nothing
Set moItemOther = goredUtil.GetItemFromID(sTemp, moOlFld.EntryID)
goAppProc.SetPropsInNamedProps moItemOther ' here the named
properties are set

before this procedure finishes I print the item ID which is saved in a named
property:
Debug.Print "id= " & goFldMon.GetItemID(moItemOther) ' this
returns the ID from the named property
here I see the CORRECT id so the named property is still there.
Then I open the task in outlookspy and... all the named properties,
including the ID are gone...

I have several customers who are reporting problems which can be traced back
to this behaviour. They ALL have SP2 installed.... Unfortunately on all my
computers I have applied sp2 already so can't test without sp2 anymore or
I'll have to reinstall outlook.
Do you have any more ideas?

Ronald
 
Move is a function that returns the new item, not a sub. The old item is no
longer valid and must be immediately released.
Change the line
moItemOther.Move moOlFld
to
set moItemOther = moItemOther.Move(moOlFld)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Hi Ken,

No, .oft doesn't work. It already didn't work before SP2. An .oft file saved
with the redemption SaveAs can't be imported either with
oOutlook.CreateItemFromTemplate or with redemption's
utils.GetItemFromMsgFile or with redemption's item.import.

I did find a way to import the item from a .msg file in the correct folder
and to retain it's named properties:
Set moItemOther = moOlFld.Items.Add()
moredApp.item = moItemOther
moredApp.Import msMsgFile, olMSG
BUT...
this totally messes up the recurrance info. So a recurrant appointment saved
in the .msg file and imported again (on another computer) by the above code
has totally wrong recurrance info! Even the item.isrecurring property isn't
correct anymore, it's now always false.
So this workaround for the broken .CreateItemFromTemplate method brings me
in another mess... Before SP2 and by using the .CreateItemFromTemplate
method the recurrance info stayed the same between exporting and exporting a
msg file.

Ronald
 
Hi Dmitry,

I found the solution. The problem was that MAPIUtils.GetItemFromID doesn't
work but NameSpace.GetItemFromID does.
Here's the code that works:
Set moItemOther = goOutl.CreateItemFromTemplate(msMsgFile, moOlFld)
moItemOther.Save
' the CreateItemFromTemplate method imports ALWAYS in the default
folder after Outlook 2003 SP2
' is installed. Also SP2 change: named props are lost. Workaround:
move explicitly;
' save and recreate object before setting the named props.
If moItemOther.Parent.EntryID <> moOlFld.EntryID Then
Set moItemOther = moItemOther.Move(moOlFld)
End If
DoEvents
Sleep 100
moItemOther.Subject = moItemOther.Subject
moItemOther.Save
sTemp = moItemOther.EntryID
Set moItemOther = Nothing
'Set moItemOther = goredUtil.GetItemFromID(sTemp, moOlFld.EntryID)
' doesn't work; moItemOther is nothing so use namespace method:
Set moItemOther = goNS.GetItemFromID(sTemp)

About the named properties that were lost: I now understand this is by
design in SP2 after reading this article:
http://support.microsoft.com/kb/907985/en-us?spid=2520

Ronald
 
Back
Top