OL2000: How to Programmatically Change Company Name for Multiple Contacts (239712)



The information in this article applies to:

  • Microsoft Outlook 2000

This article was previously published under Q239712

SUMMARY

This article explains how you can programmatically change the Company name for many contact entries without manually editing each contact. This can be useful when a company changes its name.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

To Programmatically Change the Company Name

NOTE: Make sure to change "Old Company" and "New Company" in the code, to reflect the old and new company names.
  1. Open a new Contact item.
  2. On the Tools menu, point to Forms, and then click Design This Form.
  3. On the Form menu, click Control Toolbox. Drag a CommandButton to the General tab of the open form.
  4. On the Form menu, click View Code, to open the Script Editor.
  5. In the Script Editor, type the following code:
    Sub CommandButton1_Click()
        Set objNameSpace = Application.GetNamespace("MAPI")
        Set objContactsFolder = objNameSpace.GetDefaultFolder(10)
        Set objContacts = objContactsFolder.Items.Restrict("[MessageClass] _
            = 'IPM.Contact'")
        For Each objContact In objContacts
            If objContact.CompanyName = "Old Company" Then
                objContact.CompanyName = "New Company"
                objContact.Save
            End If
        Next
    End Sub
    					
  6. On the Script Editor File menu, click Close.
  7. On the Form menu, click Run this Form.
  8. Click the CommandButton, this is CommandButton1 unless you renamed the button.
  9. Open your contacts, and check that the company name is changed to the new name.

REFERENCES


Modification Type:MajorLast Reviewed:9/29/2003
Keywords:kbhowto kbProgramming KB239712