OL2000: How to Change the File As Field for All Contacts (269172)



The information in this article applies to:

  • Microsoft Outlook 2000

This article was previously published under Q269172

SUMMARY

This article describes how to use a custom Outlook form and Visual Basic Scripting Edition (VBScript) to programmatically change the File As field for a large number of existing contacts.

MORE INFORMATION

IMPORTANT: If you change the format of the File As field by using the standard Outlook contact form, Outlook ensures that the format of this field does not affect other areas where this type of information is displayed (such as at the top of a contact when you view it in the Address Cards view). However, this example simply changes the File As field itself and therefore does not perform the same function as the Outlook contact form. Microsoft recommends that you make a copy of your contacts folder and then use the sample code below on the folder that you copied to ensure that the benefits of using this sample outweigh any potential shortcomings of this approach.

NOTE: When you change the File As field, the order in which the contacts appear in the Outlook Address Book is not affected.

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: When you create a new custom Outlook form, you can change the File As field for all contacts to any of the following formats:
  • First Last
  • Last, First
  • Company
  • Last, First (Company)
  • Company (Last, First)

How to Design the Custom Form

  1. On the File menu, point to New, and then click Mail Message to open a new e-mail message.
  2. On the Tools menu of the new e-mail message, point to Forms, and then click Design This Form.
  3. Insert five Command buttons on the new form. To do this:
    1. Click the (P.2) tab to go to a blank page on the form.
    2. On the Form menu, click Control Toolbox, click CommandButton, and then drag the button to the blank form page.
    3. Right-click the new button, click Properties, and then type cmdLastFirst in the Name box.
    4. In the Caption box, type Last, First, and then click OK.
    5. In the Toolbox dialog box, click CommandButton, and then drag a second button to the blank form page.
    6. Right-click the new button, click Properties, and then type cmdFirstLast in the Name box.
    7. In the Caption box, type First Last, and then click OK.
    8. In the Toolbox dialog box, click CommandButton, and then drag a third button to the blank form page.
    9. Right-click the new button, click Properties, and then type cmdCompany in the Name box.
    10. In the Caption box, type Company, and then click OK.
    11. In the Toolbox dialog box, click CommandButton, and then drag a fourth button to the blank form page.
    12. Right-click the new button, click Properties, and then type cmdLastFirstCompany in the Name box.
    13. In the Caption box, type Last, First (Company), and then click OK.
    14. In the Toolbox dialog box, click CommandButton, and then drag a fifth button to the blank form page.
    15. Right-click the new button, click Properties, and then type cmdCompanyLastFirst in the Name box.
    16. In the Caption box, type Company (Last, First), and then click OK.
  4. Type the following Visual Basic Scripting Edition (VBScript) code. To do this:
    1. On the Form menu, click View Code to open the Script Editor.
    2. In the Script Editor, type or copy the following code:
      Option Explicit
      Dim strSortBy
      
      Sub cmdLastFirst_Click()
         strSortBy = "LastFirst"
         UpdateContacts
      End Sub
      
      Sub cmdFirstLast_Click()
         strSortBy = "FirstLast"
         UpdateContacts
      End Sub
      
      Sub cmdCompany_Click()
         strSortBy = "Company"
         UpdateContacts
      End Sub
      
      Sub cmdLastFirstCompany_Click()
         strSortBy = "Last, First (Company)"
         UpdateContacts
      End Sub
      
      Sub cmdCompanyLastFirst_Click()
         strSortBy = "Company (Last, First)"
         UpdateContacts
      End Sub
      
      Sub UpdateContacts()
      
         Dim CurFolder
         Dim MyItems
         Dim MyItem
         Dim NumItems, i
      
         ' Use whichever folder is currently selected
         Set CurFolder = Application.ActiveExplorer.CurrentFolder
      
         ' Make sure it's a contact folder
         If CurFolder.DefaultItemType = 2 Then
            MsgBox "This process may take some time. You will be " & _
            "notified when complete.", , "Contact Tools Message"
            Set MyItems = CurFolder.Items
            NumItems = MyItems.Count
            For i = 1 to NumItems
               Set MyItem = MyItems.Item(i)
               ' Make sure it's not a distribution list in the folder
               ' (really only applies to OL98 and OL2000)
               If TypeName(MyItem) = "ContactItem" Then
                  Select Case strSortBy
                     Case "LastFirst"
                        If MyItem.LastNameandFirstName <> "" Then
                           MyItem.FileAs = MyItem.LastNameandFirstName
                        Else
                           MyItem.FileAs = MyItem.CompanyName
                        End IF
                     Case "FirstLast"
                        If MyItem.Subject <> "" Then
                           MyItem.FileAs = MyItem.Subject
                        Else
                           MyItem.FileAs = MyItem.CompanyName
                        End IF
                     Case "Company"
                        If MyItem.CompanyName <> "" Then
                           MyItem.FileAs = MyItem.CompanyName
                        Else
                           MyItem.FileAs = MyItem.LastNameandFirstName
                        End IF
                     Case "Last, First (Company)"
                        MyItem.FileAs = MyItem.LastNameAndFirstName
                        If MyItem.CompanyName <> "" Then
                           If MyItem.FileAs <> "" Then
                              MyItem.FileAs = MyItem.FileAs & " (" & _
                                              MyItem.CompanyName & ")"
                           Else
                              MyItem.FileAs = MyItem.FileAs & _
                                        MyItem.CompanyName
                           End If
                        End If
                     Case "Company (Last, First)"
                        MyItem.FileAs = MyItem.CompanyName
                        If MyItem.LastNameandFirstName <> "" Then
                           If MyItem.FileAs <> "" Then
                              MyItem.FileAs = MyItem.FileAs & " (" & _
                                     MyItem.LastNameAndFirstName & ")"
                           Else
                              MyItem.FileAs = MyItem.FileAs & _
                                     MyItem.LastNameAndFirstName
                           End If
                        End If
                  End Select
                  MyItem.Save
               End If           ' check TypeName
            Next
            MsgBox "Finished updating contacts."
         Else
            MsgBox "The current folder must be a contacts folder."
         End If                 ' check contacts folder
      
         Set MyItem = Nothing
         Set MyItems = Nothing
         Set CurFolder = Nothing
      
      End Sub
      						
    3. On the File menu in Script Editor, click Close to return to the form.
    4. Click the Message page of the form.
    5. On the Form menu, click Display This Page. This hides the form page so that it does not appear when the form is used.
  5. Publish the form. To do this:
    1. On the Tools menu, point to Forms, and then click Publish Form As.
    2. Verify that next to the Look in button you see Personal Forms Library.
    3. In the Display name box, type a discriptive name for your new form (such as, Change File As fields), and then click Publish.
    4. When you are prompted to save the form definition with the item, click No.
    5. Close the message without saving it.

How to Use the Custom Form

To use your new form:
  1. Locate the Contact folder that you want to re-sequence.
  2. On the File menu, point to New, and then click Choose Form.
  3. Change the Look in box to Personal Forms Library, click your new form, and then click OK.
  4. Click the appropriate button to update the File As field.

REFERENCES

For additional information about available resources and answersto commonly asked questions about Microsoft Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:

146636 OL2000: Questions About Custom Forms and Outlook Solutions


Modification Type:MajorLast Reviewed:10/8/2003
Keywords:kbhowto KB269172