Contacts - Using VBA to change FileAs Property

  • Thread starter Thread starter Alan
  • Start date Start date
A

Alan

Hi All,

I am trying to use VBA to change the FileAs property of all the
contacts within a given contacts folder to the Company Name for that
contact (every contact always has something in the Company Name
field).

The code I have so far is posted below (I am quite a newbie so it may
not be the most efficient, but time is not an issue - just getting it
working!)

It *seems* to work, even to the point that the unnecessary line that
reads "FileAs = .FileAs" confirms via the locals window that the
FileAs property for the item has been changed as expected.

However, once the code has run, when I return to the contact folder,
the items still have their original FileAs settings.

Any help is much appreciated.

Regards,

Alan.


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Sub FileAs_ToCompany()

Dim objNS As NameSpace

Dim FolderCollection As Folders

Dim AlanMainMailFileFolders As Folders
Dim AlanContactsFolders As Folders
Dim ImportedClientEmailAddressesItems As Items


Set objNS = Application.GetNamespace("MAPI")


Set FolderCollection = Application.GetNamespace("MAPI").Folders

Set AlanMainMailFileFolders = FolderCollection("Alan - Main Mail
File").Folders
Set AlanContactsFolders =
AlanMainMailFileFolders("Contacts").Folders
Set ImportedClientEmailAddressesItems =
AlanContactsFolders("Imported Client Email Addresses").Items

Set FolderCollection = Nothing

Set AlanMainMailFileFolders = Nothing
Set AlanContactsFolders = Nothing

Set objNS = Nothing




For Counter = 1 To ImportedClientEmailAddressesItems.Count

Set ContactItem = ImportedClientEmailAddressesItems(Counter)


Company = ContactItem.CompanyName

With ContactItem

.FileAs = Company

FileAs = .FileAs

End With

Next Counter

End Sub


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
You forgot to include a Save statement to save the item with the changes.
 
Sue Mosher said:
You forgot to include a Save statement to save the item with the
changes.

Doh Doh Doh

[Bangs head repeatedly on keyboard and looks rather sheepish]

Thank you very much Sue - I really appreciate your help.

Alan.
 
Been there, done that myself. Once you stop beating your head against the
wall, it really does feel better.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Alan said:
Sue Mosher said:
You forgot to include a Save statement to save the item with the
changes.

Doh Doh Doh

[Bangs head repeatedly on keyboard and looks rather sheepish]

Thank you very much Sue - I really appreciate your help.

Alan.
 
Back
Top