Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Add New Record to a Combo Box with Double-Click


View products that this article applies to.

This article was previously published under Q209836
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

↑ Back to the top


Summary

This article describes how to set up a macro so that you can add new values to a combo box. The article uses the Orders form in the sample database Northwind.mdb as an example.

↑ Back to the top


More information

Follow these steps to modify the Orders form so that you can add new values to the Salesperson combo box:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Open the sample database Northwind.mdb.
  2. Create the following new macro, and save it as Macro1:
       Macro Name   Condition                   Action
       -----------------------------------------------------
       NewRecord                                OpenForm
       OnClose      [EmployeeID] Is Not Null    RunCommand
                    ...                         SelectObject
                    ...                         ReQuery
                    ...                         SetValue
    
       NewRecord Actions
       ---------------------------------------------------------
       OpenForm
          Form Name: Employees
          View: Form
          Data Mode: Add
          Window Mode: Normal
    
       OnClose Actions
       ----------------------------------------------
       RunCommand
          Command: SaveRecord
       SelectObject
          Object Type: Form
          Object Name: Orders
          In Database Window: No
       ReQuery
          ControlName: EmployeeId
       SetValue
          Item: [Forms]![Orders]![EmployeeID]
          Expression: [Forms]![Employees]![EmployeeID]
    					
  3. Change the properties of the EmployeeID combo box on the Orders form as follows:
       OnDblClick: Macro1.NewRecord
       StatusBarText: Double-click to Add a New Employee
    					
  4. Change the OnClose property of the Employees form as follows:
       On Close: Macro1.OnClose
    					
To see how this works, open the Orders form in Form view, and then double-click the Salesperson combo box. Note that the Employees form opens. After you add a new record, close the Employees form. The new employee's name appears on the Orders form.

↑ Back to the top


Keywords: KB209836, kbhowto

↑ Back to the top

Article Info
Article ID : 209836
Revision : 2
Created on : 6/30/2004
Published on : 6/30/2004
Exists online : False
Views : 336