Copying the content of a field into another field for all the records of a folder using VB?


  • Hello,

    I'm new to VB in Outlook and would appreciate some direction.  I have a public folder database the uses a custom form based on the calendar form.  Users of the database are using either Outlook 2007/Outlook 2010 clients.

    The database includes 4 fields Type and TypeA (both alpha-num)and Num and NumA (both numeric)

    What I'm trying to accomplish would be to have a toolbar button for the manager (not the users) of this folder that when pressed would copy the values of Type to TypeA and Num to NumA for every record in the database.  This would allow TypeA and NumA to remain static (a "snapshot") while Type and Num could change as users change records.

    As an aside, if at the same time I could have it delete the contents of 2 fields for all the records in a database(Set1 and Cost) that would be very helpful.

    Is this possible?

    Thanks in advance for any assistance that can be given!

    Monday, January 14, 2013 4:02 AM


  • Those custom fields will be accessible in every AppointmentItem object as a UserProperty object in the AppointmentItem.UserProperties collection. Use UserProperties.Find("TypeA", True) to get each UserProperty object for each custom field, and set UserProperty.Value to the value you want.

    To get all appointments in the Calendar, you need to get a reference to the Folder object. One way is this:

    How to: Obtain a Folder Object from a Folder Path:

    You can also use:

    • NameSpace.GetDefaultFolder(olPublicFoldersAllPublicFolders), then call Folder.Folders("subfoldername") until you get the folder level you need in the hierarchy
    • NameSpace.GetFolderFromID (if you know the EntryID value of the Public Folder and the StoreID for the Public Folder store)
    • NameSpace.PickFolder to force the user to choose the folder so you can use the returned Folder object in code
    • Explorer.CurrentFolder

    Once you have a Folder object, iterate through the Folder.Items object to get each AppointmentItem object and work with the custom fields:

    Enumerating, Searching, and Filtering Items in a Folder:

    As for calling your code with a custom button, you should use a COM Add-in to do that. You'd have to use both CommandBar and IRibbonControl objects to support both Outlook 2007 and 2010 clients.

    Eric Legault MVP (Outlook)
    About me...
    Outlook Appins: Store Social Media fields in your Outlook Contacts!

    Monday, January 14, 2013 3:41 PM