Microsoft KB Archive/201100

From BetaArchive Wiki

Article ID: 201100

Article Last Modified on 11/23/2006



APPLIES TO

  • Microsoft Outlook 2000 Standard Edition



This article was previously published under Q201100


SUMMARY

This article describes how you can use Microsoft Visual Basic Scripting Edition (VBScript) and Outlook to populate a ComboBox control with the FullName field of all of your contacts.

MORE INFORMATION

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:

This example contains four steps.

  • Create a new Contact form and place a ComboBox1 control on the form.
  • Create the VBScript code that populates ComboBox1 with the FullName field of all of your contacts.
  • Publish the new form so that the Item_Open event runs when you open the new Contact form.
  • Use the new form to expose the combo box list containing your contacts.

Create a New Contact Form and ComboBox1 Control

  1. On the File menu, point to New, and then click Contact.
  2. On the Tools menu, point to Forms, and then click Design This Form.
  3. Click the P.2 tab in the form.
  4. On the Form menu, click Display This Page.
  5. On the Form menu, click Rename Page. In the Page Name box, type TabName, and then click OK.
  6. On the Form menu, click Control Toolbox. Drag the ComboBox control to the form TabName page.

Create the VBScript Code to Populate ComboBox1

  1. On the Form menu, click View Code. This opens the Script Editor.
  2. Type the following code in the Script Editor.

    Sub Item_Open
    
       ' Set the NameSpace object
       Set objOLNS = Application.GetNameSpace("MAPI")
    
       ' Set the Contacts folder, which is in the MAPI NameSpace
       Set objContactFolder = objOLNS.GetDefaultFolder(10)
    
       ' Set the collection of all Contact items
       Set objAllContacts = objContactFolder.Items
    
       ' Set the object referring to the form page the combo box is on
       Set objFormTab = Item.GetInspector.ModifiedFormPages("TabName")
    
       ' Set the object referring to the combo box
       Set objCombo = objFormTab.Controls("ComboBox1")
    
       ' Loop through all of the contacts
       For Each Contact in objAllContacts
          ' Add the current contact's full name to the combo box
          objCombo.AddItem Contact.FullName
       Next
    End Sub
                        
  3. In the Script Editor, on the File menu, click Close.

Publish the New Contact Form

  1. In the form, on the Tools menu, point to Forms and then click Publish Form As.
  2. Confirm that Look In is set to Outlook Folders and the Contacts folder is selected.
  3. In the Display name box, type a name for the form, and then click Publish.
  4. On the File menu, click Close. When prompted to save changes, click No so that a new item is not created.

Using the New Contact Form

  1. Open your Contacts folder.
  2. On the Actions menu, click the new form name to open your newly published form.
  3. In the new form, click the TabName tab.
  4. On the TabName page of the form, you will see a single ComboBox control. If you click to display the combo box list, you will see a list containing the full name of all of your contacts.


REFERENCES

For additional information about available resources and answers to commonly asked questions about Microsoft Outlook 2000 solutions, please see the following article in the Microsoft Knowledge Base:

146636 OL2000: Questions About Custom Forms and Outlook Solutions



Additional query words: OutSol OutSol2000 higher OL2K list box listbox

Keywords: kbcode kbhowto kbprogramming KB201100