Ouch. This help is for Outlook 2002 and differs slightly for Outlook
2003. Fortunately, the code itself works with just a simple copy and
paste but some of the instructions on other aspects of the procedure
are incorrect.
Here's my revised instructions for Outlook 2003 ('No warranties if
this screws anything up' usual blah blah applies)...
Anything '*' is a change to the original instructions (bracketed
comments are MS's old instructions that needed changing.)
----
1*. Just ignore this bit completely
(1. On the File menu, point to New, and then click Mail Message to
open a new e-mail message. )
2*. Highlight the Contacts folder, In the Tools menu, point to Forms,
and then click 'Design a Form'.
(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:a. Click
the (P.2) tab to go to a blank page on the form.
b. On the Form menu, click Control Toolbox, click CommandButton, and
then drag the button to the blank form page.
c. Right-click the new button, click Properties, and then type
cmdLastFirst in the Name box.
d. In the Caption box, type Last, First, and then click OK.
e. In the Toolbox dialog box, click CommandButton, and then drag a
second button to the blank form page.
f. Right-click the new button, click Properties, and then type
cmdFirstLast in the Name box.
g. In the Caption box, type First Last, and then click OK.
h. In the Toolbox dialog box, click CommandButton, and then drag a
third button to the blank form page.
i. Right-click the new button, click Properties, and then type
cmdCompany in the Name box.
j. In the Caption box, type Company, and then click OK.
k. In the Toolbox dialog box, click CommandButton, and then drag a
fourth button to the blank form page.
l. Right-click the new button, click Properties, and then type
cmdLastFirstCompany in the Name box.
m. In the Caption box, type Last, First (Company), and then click OK.
n. In the Toolbox dialog box, click CommandButton, and then drag a
fifth button to the blank form page.
o. Right-click the new button, click Properties, and then type
cmdCompanyLastFirst in the Name box.
p. 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:a. On the Form menu, click View Code to open the Script
Editor.
b. 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
c. On the File menu in Script Editor, click Close to return to the
form.
d*. Highlight p.2 tab
(d. Click the Message page of the form.)
e* On the Form menu, make sure 'Display this Page' is highlighted.
Advice form Microsoft meant I could not access the new form at all.
(e. 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:a. On the Tools menu, point to Forms,
and then click Publish Form As.
b. Verify that next to the Look in button you see Personal Forms
Library.
c. In the Display name box, type a discriptive name for your new form
(such as, Change File As fields), and then click Publish.
d. When you are prompted to save the form definition with the item,
click No.
e. Close the message without saving it.
Back to the top
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.
----
Well that's it. Still a little of an untidy way to do things but at
least it works. I also managed to modify the code so that I got
"First, Last (Company)" which isn't usually an option. I'm still
waiting to see if that's a dangerous thing to attempt but so far
things seem to be working out fine.