PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Save method does not save changes

Reply

Save method does not save changes

 
Thread Tools Rate Thread
Old 30-06-2005, 03:35 PM   #1
ErdoesiT
Guest
 
Posts: n/a
Default Save method does not save changes


Hi,

I am trying write a VBA script that to copies a ContactItem and then
modifies the original item and its copy. Unfortunately the changes to
the source item are ignored.

The following piece of code can be used to reproduce this behaviour:


Public Sub Test()
Dim Namespace As Namespace
Dim Folder As MAPIFolder

Dim SourceItem As ContactItem
Dim TargetItem As ContactItem

Set Namespace = GetNamespace("MAPI")
Set Folder = Namespace.GetDefaultFolder(olFolderContacts)

'Copy first item in default contacts folder
Set SourceItem = Folder.Items(1)
Set TargetItem = SourceItem.Copy

'Modify source and target item
SourceItem.Body = "TargetItem: " & TargetItem.EntryID
TargetItem.Body = "SourceItem: " & SourceItem.EntryID

'Save changes
SourceItem.Save
TargetItem.Save
End Sub


Can anybody there tell me what's wrong with this script?

Thomas

  Reply With Quote
Old 30-06-2005, 03:56 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Save method does not save changes

Make sure you dererence all objects by setting them to Nothing before you try to open them in the UI.

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


"ErdoesiT" <thomas.erdoesi@web.de> wrote in message news:1120142125.579629.224310@f14g2000cwb.googlegroups.com...
> Hi,
>
> I am trying write a VBA script that to copies a ContactItem and then
> modifies the original item and its copy. Unfortunately the changes to
> the source item are ignored.
>
> The following piece of code can be used to reproduce this behaviour:
>
>
> Public Sub Test()
> Dim Namespace As Namespace
> Dim Folder As MAPIFolder
>
> Dim SourceItem As ContactItem
> Dim TargetItem As ContactItem
>
> Set Namespace = GetNamespace("MAPI")
> Set Folder = Namespace.GetDefaultFolder(olFolderContacts)
>
> 'Copy first item in default contacts folder
> Set SourceItem = Folder.Items(1)
> Set TargetItem = SourceItem.Copy
>
> 'Modify source and target item
> SourceItem.Body = "TargetItem: " & TargetItem.EntryID
> TargetItem.Body = "SourceItem: " & SourceItem.EntryID
>
> 'Save changes
> SourceItem.Save
> TargetItem.Save
> End Sub
>
>
> Can anybody there tell me what's wrong with this script?
>
> Thomas
>

  Reply With Quote
Old 01-07-2005, 09:14 AM   #3
ErdoesiT
Guest
 
Posts: n/a
Default Re: Save method does not save changes

Hi Sue,

Thanks for your reply. I added the following lines but unfortunately
this did not change the behaviour of the coding. :-(

Set SourceItem = Nothing
Set TargetItem = Nothing
Set Folder = Nothing
Set Namespace = Nothing

Thomas

  Reply With Quote
Old 01-07-2005, 09:35 AM   #4
ErdoesiT
Guest
 
Posts: n/a
Default Re: Save method does not save changes

Finally I found a workaround to solve the problem:


Public Sub Test()
Dim Namespace As Namespace
Dim Folder As MAPIFolder

Dim SourceItem As ContactItem
Dim TargetItem As ContactItem

Set Namespace = GetNamespace("MAPI")
Set Folder = Namespace.GetDefaultFolder(olFolderContacts)

Set SourceItem = Folder.Items(1)
Set TargetItem = SourceItem.Copy
Set SourceItem = Nothing
Set SourceItem = Folder.Items(1)

SourceItem.Body = "TargetItem: " & TargetItem.EntryID
TargetItem.Body = "SourceItem: " & SourceItem.EntryID

SourceItem.Save
TargetItem.Save
End Sub


It seems that a ContactItem becomes unusable after calling the
Copy-Method.
Unfortunately this means that I have to change a lot of coding because
I cannot use a Collection to store ContactItems...

Of course Microsoft will be able to explain why this ist not a bug but
a feature...

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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