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 Start Macros, Functions, and Applications from a Combo or List Box


View products that this article applies to.

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

This article applies only to a Microsoft Access database (.mdb).

↑ Back to the top


Summary

This article describes how to start a macro, a function, or another Microsoft Windows-based application by selecting it from a combo box or list box on a Microsoft Access form.

↑ Back to the top


More information

To create a combo box or list box that starts a macro, a function, or another Windows-based application, follow these steps:
  1. Start Microsoft Access and create a new, blank database.
  2. Create the following table to supply the combo box or list box with a list of available items:
       Table: Activities
       ---------------------------
       Field Name: ItemName
          Data Type: Text
          Field Size: 50
       Field Name: ItemDescription
          Data Type: Text
          Field Size: 50
       Field Name: ItemType
          Data Type: Text
          Field Size: 12
    					
  3. Fill the table that you created in step 2 with the macros, functions, and Windows-based applications that you want to have listed in the combo box or list box. Note that any applications listed in the table must be .com or .exe files. You cannot include .hlp or other non-executable files from a macro. Use the following tags in the ItemType field:
       Item                  ItemType
       ------------------------------
       macro                 Macro
       function              Function
       Windows application   App
    					
    For example, you might create the following entries in the table:
       ItemName              ItemDescription          ItemType
       -------------------------------------------------------
       CALC.EXE              Run Windows Calculator   App
       Notepad               Run Windows Notepad      App
       Macro1                Run Macro 1              Macro
       MyFunc()              Run MyFunc()             Function
    					
  4. Create a new, blank form.
  5. Add a combo box or list box with the following properties to the form:
       Combo or List Box
       ---------------------------------------------------
       Name: cboSelect
       RowSourceType: Table/Query
       RowSource: Activities (the table created in step 1)
       ColumnCount: 3
       ColumnWidths: 0; 2; 0
       BoundColumn: 1
       AfterUpdate: mcrMyForm
    					
  6. Save the form as MyForm.
  7. Create a new macro with the following actions. Save the macro as mcrMyForm.NOTE: If the Conditions column is not visible, click Conditions on the View menu.
       Condition                                         Action
       ----------------------------------------------------------
       Forms![MyForm]![cboSelect].Column(2)="Macro"      RunMacro
       Forms![MyForm]![cboSelect].Column(2)="Function"   RunCode
       Forms![MyForm]![cboSelect].Column(2)="App"        RunApp
    
       mcrMyForm Actions
       -----------------------------------------------
       RunMacro
          MacroName: =Forms![MyForm]![cboSeFect]
       RunCode
          FunctionName: =Forms![MyForm]![cboSelect]
       RunApp
          ApplicationName: =Forms![MyForm]![cboSelect]
    					
  8. View the MyForm form in Form view. Select any entry in the combo box or list box to start the associated item.

↑ Back to the top


References

For more information about using a combo box or list box, click Microsoft Access Help on the Help menu, type create a bound or unbound combo box, drop-down list box, or list box in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top


Keywords: KB209011, kbusage, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 209011
Revision : 2
Created on : 6/28/2004
Published on : 6/28/2004
Exists online : False
Views : 280