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

Last reviewed: April 2, 1997
Article ID: Q117910
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0, 97

SUMMARY

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

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:

  1. 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
    
    

  2. 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
    
    

  3. Create a new, blank form.

  4. 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
    

  5. Save the form as MyForm.

  6. 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]![cboSelect]
          RunCode
             FunctionName: =Forms![MyForm]![cboSelect]
          RunApp
             ApplicationName: =Forms![MyForm]![cboSelect]
    
    

  7. View the MyForm form in Form view. Select any entry in the combo box or list box to start the associated item.

REFERENCES

For more information about using a combo box, search the Help Index for "creating combo boxes," or ask the Microsoft Access 97 Office Assistant.

For more information about using a list box, search the Help Index for "creating list boxes," or ask the Microsoft Access 97 Office Assistant.


Keywords : kbusage McrOthr
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.