How can I get this code to work?

R

Richard

This is the form for the File as;
Here is the code from the form on this MS Help and Support page:
http://support.microsoft.com/default.aspx?scid=kb;en-us;291144

this is the code (see below) for just one of the five buttons, the Company
Last, First. I want to tweak the code to do Company First Last so that it
shows- File As :
Company
First Last
or, if there is no company associated with that contact, to show First
Last.
in my contacts. (I use the "address cards" view)
Code as follows:
----------------------------------------------------------------------------
--
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

----------------------------------------------------------------------------
-----------------------------

I have tried several attempts to either get an error or on one attemp I got
the first part of the code to work but any contact that had no company
associated with it was shown blank. (PS the parenthesis is as is from the
code I copied)
 
S

Sue Mosher [MVP-Outlook]

You need to test for the presence of data in the Company field and then
build FileAs accordingly, maybe something like:

If MyItem.CompanyName = "" Then
MyItem.FileAs = MyItem.FullName
Else
MyItem.FileAs = MyItem.CompanyName & vbCrLf & _
MyItem.FullName
End IF

FWIW, the code in the article you cited is incorrect. Instead of
parentheses, you need a CR/LF as in the code above.
 
R

Richard

That worked!! Oh Thank you!!


Sue Mosher said:
You need to test for the presence of data in the Company field and then
build FileAs accordingly, maybe something like:

If MyItem.CompanyName = "" Then
MyItem.FileAs = MyItem.FullName
Else
MyItem.FileAs = MyItem.CompanyName & vbCrLf & _
MyItem.FullName
End IF

FWIW, the code in the article you cited is incorrect. Instead of
parentheses, you need a CR/LF as in the code above.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top