ACC: Wait Argument in SendKeys May Not Stop Macro Processing

Last reviewed: August 6, 1997
Article ID: Q95449
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SYMPTOMS

Advanced: Requires expert coding, interoperability, and multiuser skills.

When a macro calls the SendKeys action with the Wait parameter set to Yes, the macro will continue before the program that processed the keystrokes has finished performing the action that it was called to do.

RESOLUTION

To work around this behavior, have the macro call an Access Basic function or procedure that checks to see if the other application is finished. To correct the situation described above, you can do the following:

   Macro Action
   ------------
   RunApp                - Start Microsoft Excel
   SendKeys              - Start the macro
   RunCode               - Call a module that continues checking until
                           the file exists
   TransferSpreadsheet   - Import the spreadsheet

MORE INFORMATION

For example, suppose you want to create a macro that will call Microsoft Excel to make a file and then process that file after Microsoft Excel has created it. The Microsoft Access macro calls RunApp to start Microsoft Excel, then calls SendKeys to start a Microsoft Excel macro with the Wait parameter set to Yes. Microsoft Access will wait until the key strokes are processed, then continue if the Microsoft Excel macro has not finished creating the file. Microsoft Access will not wait for Microsoft Excel, and will fail when it tries to use the file.

The SendKeys action in Microsoft Access has two arguments: the first argument indicates which keystrokes to send; the second argument causes Microsoft Access to pause until the keystrokes are processed.

The description of the Wait argument on page 432 of the Microsoft Access "Language Reference" manual is misleading. If Wait is Yes, Microsoft Access will only wait until the keystrokes are processed. It will not wait until the application that the keystrokes were sent to is finished.

For more information about checking for a process to finish, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q99940
   TITLE     : ACC: How to Wait for a Shelled Process to Finish
Keywords          : McrArg kbusage
Version           : 1.0 1.1 2.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbprb
Solution Type     : kbworkaround


================================================================================


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: August 6, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.