Microsoft KB Archive/264279

= OL98: How to Change the File As Field for All Contacts =

Article ID: 264279

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Outlook 98 Standard Edition

-



This article was previously published under Q264279





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:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

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
 On the File menu, point to New, and then click Mail Message to open a new e-mail message. On the Tools menu of the new e-mail message, point to Forms, and then click Design This Form. Insert five Command buttons on the new form. To do this:  Click the (P.2) tab to go to a blank page on the form. On the Form menu, click Control Toolbox, click CommandButton, and then drag the button to the blank form page. Right-click the new button, click Properties, and then type cmdLastFirst in the Name box.</li> In the Caption box, type Last, First, and then click OK.</li> In the Toolbox dialog box, click CommandButton, and then drag a second button to the blank form page.</li> Right-click the new button, click Properties, and then type cmdFirstLast in the Name box.</li> In the Caption box, type First Last, and then click OK.</li> In the Toolbox dialog box, click CommandButton, and then drag a third button to the blank form page.</li> Right-click the new button, click Properties, and then type cmdCompany in the Name box.</li> In the Caption box, type Company, and then click OK.</li> In the Toolbox dialog box, click CommandButton, and then drag a fourth button to the blank form page.</li> Right-click the new button, click Properties, and then type cmdLastFirstCompany in the Name box.</li> In the Caption box, type Last, First (Company), and then click OK.</li> In the Toolbox dialog box, click CommandButton, and then drag a fifth button to the blank form page.</li> Right-click the new button, click Properties, and then type cmdCompanyLastFirst in the Name box.</li> In the Caption box, type Company (Last, First), and then click OK.</li></ol> </li> Type the following Visual Basic Scripting Edition (VBScript) code. To do this: <ol style="list-style-type: lower-alpha;"> On the Form menu, click View Code to open the Script Editor.</li>  In the Script Editor, type or copy the following code: Option Explicit Dim strSortBy

Sub cmdLastFirst_Click strSortBy = &quot;LastFirst&quot; UpdateContacts End Sub

Sub cmdFirstLast_Click strSortBy = &quot;FirstLast&quot; UpdateContacts End Sub

Sub cmdCompany_Click strSortBy = &quot;Company&quot; UpdateContacts End Sub

Sub cmdLastFirstCompany_Click strSortBy = &quot;Last, First (Company)&quot; UpdateContacts End Sub

Sub cmdCompanyLastFirst_Click strSortBy = &quot;Company (Last, First)&quot; 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 &quot;This process may take some time. You will be &quot; & _ &quot;notified when complete.&quot;,, &quot;Contact Tools Message&quot; 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) = &quot;ContactItem&quot; Then Select Case strSortBy Case &quot;LastFirst&quot; If MyItem.LastNameandFirstName <> &quot;&quot; Then MyItem.FileAs = MyItem.LastNameandFirstName Else MyItem.FileAs = MyItem.CompanyName End IF              Case &quot;FirstLast&quot; If MyItem.Subject <> &quot;&quot; Then MyItem.FileAs = MyItem.Subject Else MyItem.FileAs = MyItem.CompanyName End IF              Case &quot;Company&quot; If MyItem.CompanyName <> &quot;&quot; Then MyItem.FileAs = MyItem.CompanyName Else MyItem.FileAs = MyItem.LastNameandFirstName End IF              Case &quot;Last, First (Company)&quot; MyItem.FileAs = MyItem.LastNameAndFirstName If MyItem.CompanyName <> &quot;&quot; Then If MyItem.FileAs <> &quot;&quot; Then MyItem.FileAs = MyItem.FileAs & &quot; (&quot; & _                                       MyItem.CompanyName & &quot;)&quot; Else MyItem.FileAs = MyItem.FileAs & _ MyItem.CompanyName End If                 End If               Case &quot;Company (Last, First)&quot; MyItem.FileAs = MyItem.CompanyName If MyItem.LastNameandFirstName <> &quot;&quot; Then If MyItem.FileAs <> &quot;&quot; Then MyItem.FileAs = MyItem.FileAs & &quot; (&quot; & _                              MyItem.LastNameAndFirstName & &quot;)&quot; Else MyItem.FileAs = MyItem.FileAs & _ MyItem.LastNameAndFirstName End If                 End If            End Select MyItem.Save End If          ' check TypeName Next MsgBox &quot;Finished updating contacts.&quot; Else MsgBox &quot;The current folder must be a contacts folder.&quot; End If                ' check contacts folder

Set MyItem = Nothing Set MyItems = Nothing Set CurFolder = Nothing

End Sub </li> <li>On the File menu in Script Editor, click Close to return to the form.</li> <li>Click the Message page of the form.</li> <li>On the Form menu, click Display This Page. This hides the form page so that it does not appear when the form is used.</li></ol> </li> <li>Publish the form. To do this: <ol style="list-style-type: lower-alpha;"> <li>On the Tools menu, point to Forms, and then click Publish Form As.</li> <li>Verify that next to the Look in button you see Personal Forms Library.</li> <li>In the Display name box, type a discriptive name for your new form (such as, Change File As fields), and then click Publish.</li> <li>When you are prompted to save the form definition with the item, click No.</li> <li>Close the message without saving it.</li></ol> </li></ol>

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.

<div class="references_section">