Microsoft KB Archive/103187

= ACC: Cannot Open a Database with a DoMenuItem Macro =

Article ID: 103187

Article Last Modified on 1/18/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 Q103187



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



SYMPTOMS
When you try to open another database with a macro containing DoMenuItem (RunCommand in Access 97) and Sendkeys actions, the macro does not seem to run.



CAUSE
Microsoft Access cannot open another database while the DoMenuItem action is running in the current database. Microsoft Access does not support opening multiple databases.



RESOLUTION
To work around this behavior, use either of the following methods. The first method runs a macro from the Database window. The second method runs a macro from a button on a form.

The resolution for Microsoft Access 97 involves the OpenCurrentDatabase method. Do not confuse the OpenCurrentDatabase method with the DAO OpenDatabase method.

For more information about the OpenCurrentDatabase method and an example of its use, search the Help Index for "OpenCurrentDatabase method," or ask the Microsoft Access 97 Office Assistant.

Method 1: Running a Macro from the Database Window
To run a macro from the Database window, follow these steps:

  Create a database and create the following macro:

     Macro Name      Action OpenMDB        SendKeys

OpenMDB Actions -     SendKeys Keystrokes: %fo.MDB~ Wait: No

 Close and save the macro as OpenMDB. In the Database window, select the OpenMDB macro, and then click the Run button. Note that the macro closes the current database and opens the database you specify in the OpenMDB macro.

Method 2: Running a Macro from a Form
To run a macro from a form, follow these steps:

  Create a database and create the following macro:

<pre class="fixed_text">     Macro Name       Action -     OpenMDB2         SelectObject SendKeys

OpenMDB2 Actions -     SelectObject Object Type: Macro Object Name: OpenMDB2 In Database Window: Yes SendKeys Keystrokes: %fo<YOURFILE>.MDB~ Wait: No

</li> Create a blank form and save it as OpenMDBTest.</li>  Add a command button to the form and set the following properties for the control:

<pre class="fixed_text">     Name: Button1 Caption: Open Database

</li> Set the button's OnClick property to the OpenMDB2 macro.

NOTE: The OnClick property is called the OnPush property in version 1.x.</li> Switch the OpenMDBTest form to Form view.</li> Click the command button to close the current database and open another database.</li></ol>

<div class="moreinformation_section">

Steps to Reproduce Behavior
 Create a new database.</li>  Create the following macro in versions 1.x, 2.0, 7.0:

<pre class="fixed_text">     Macro Name   Action ---     OpenMe       SendKeys DoMenuItem

OpenMe Actions -     SendKeys NORTHWIND.MDB~ (or NWIND.MDB in versions 1.x and 2.0) DoMenuItem Menubar: Database Menu Name: File Command: Open database

- or -

Create the following macro in Microsoft Access 97 (the DoMenuItem action has been replaced with the RunCommand action):

<pre class="fixed_text">     Macro Name   Action ---     OpenMe       SendKeys RunCommand

OpenMe Actions -     SendKeys NORTHWIND.MDB~ (or NWIND.MDB in versions 1.x and 2.0) RunCommand Command: OpenDatabase

</li> Run the macro. Note that it does not open the Northwind.mdb database. Microsoft Access 97 will display the Action Failed dialog box.</li></ol>

Additional query words: opendb

Keywords: kbprb kbusage KB103187

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.