Microsoft KB Archive/117910

= ACC: How to Start a Macro from a Combo Box List of Names =

Article ID: 117910

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 1.0 Standard Edition
 * Microsoft Access 1.1 Standard Edition
 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q117910



Moderate: Requires basic macro, coding, and interoperability skills.



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.



MORE INFORMATION
The following steps describe how to create a combo box or list box that you can use to start a macro, a function, or another Windows-based application:

  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   Fill the table you created in step 1 with the macros, functions, and Windows-based applications that you want to be 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 ---     C:\WINDOWS\CALC.EXE   Run Windows Calculator   App Notepad              Run Windows Notepad      App Macro1               Run Macro 1              Macro MyFunc             Run MyFunc             Function  Create a new, blank form.  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.Main  Save the form as MyForm.</li>  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.)

<pre class="fixed_text">     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]![cboSelect] RunCode FunctionName: =Forms![MyForm]![cboSelect] RunApp ApplicationName: =Forms![MyForm]![cboSelect] </li> View the MyForm form in Form view. Select any entry in the combo box or list box to start the associated item.</li></ol>

<div class="references_section">