PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Save method does not save changes
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Save method does not save changes
![]() |
Save method does not save changes |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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... |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

