Microsoft KB Archive/263572

= How To Extract MAPI Properties of Current User in Outlook Form =

Article ID: 263572

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Exchange Server 5.5 Standard Edition
 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21
 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Outlook 98 Standard Edition
 * Microsoft Outlook 97 Standard Edition

-



This article was previously published under Q263572



SUMMARY
The Outlook object model provides only basic information about the current user, such as name, address, manager's name, and so on. You can use the Collaboration Data Objects (CDO) library within an Outlook form or add-in to provide more detailed information.



MORE INFORMATION
 Create a new Outlook form. To do this, on the Tools menu, click Forms, and then click Design a Form. In the Type window, click Message. Click the (P.2) tab. On the Form menu, click Control Toolbox to display the Control Toolbox. Add a command button to the form. By default, the name of the new button is CommandButton1.  On the Form menu, click View Code to open the form script window, and then insert the following code into the window: Sub CommandButton1_Click 'Get data from Session.CurrentUser.

Dim cdoSession 'As MAPI.Session Dim cdoAddrEntry 'As AddressEntry Dim strData 'as string

'VBScript does not recognize constants! ' Define them explicitly or use their value. dim cdoPR_Account dim cdoPR_Office_Location dim cdoPR_EntryID dim cdoPR_Business_Telephone_Number Dim vbCRLF

cdoPR_Account = &h3a00001e cdoPR_Office_Location = &h3a19001e cdoPR_EntryID = &h0fff0102 cdoPR_Business_Telephone_Number = &h3a08001f vbCRLF = chr(13) & chr(10)

on error resume next

'Start the CDO code to find a match. Set cdoSession = CreateObject(&quot;Mapi.session&quot;) cdoSession.Logon ,,false,false,0  'Use the existing Outlook session. if err.number <> 0 then msgbox &quot;ERROR in logon: &quot; & err.number & vbCRLF & err.description

'Get the AddressEntry of the recipient/current user. Set cdoAddrEntry = cdoSession.CurrentUser if err.number <> 0 then msgbox &quot;ERROR getting AddressEntry: &quot; & err.number & vbCRLF & err.description

'Get properties. strData = &quot;Account: &quot; & cdoAddrEntry.fields(cdoPR_Account) strData = strData & vbCRLF & &quot;Location: &quot; & cdoAddrEntry.fields(cdoPR_Office_Location) strData = strData & vbCRLF & &quot;Business Telephone Number: &quot; & cdoAddrEntry.fields(cdoPR_Business_Telephone_Number)

Msgbox strData, 64, &quot;Information about current Outlook User&quot;

'Explicitly release objects. cdoSession.logoff

Set cdoAddrEntry = Nothing Set cdoSession = Nothing End Sub  Close the form script window. On the Form menu, click Run This Form to run the form. Click the (P.2) tab and then click the command button. Message boxes display the current user's name, location, and business phone number.</ol>

<div class="references_section">