Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
HOW TO: Determine When a Shelled Process Ends in Access 2000
Article ID: 209876 - View products that this article applies to.
This article was previously published under Q209876
Advanced: Requires expert coding, interoperability, and multiuser skills.
When you run the Shell() function in a Visual Basic for Applications procedure, it starts an executable program asynchronously and returns control to the procedure. This shelled program continues to run independently of your procedure until you close it.
If your procedure needs to wait for the shelled process to end, you can use the Windows API to poll the status of the application, but this is not very efficient. This article shows you a more efficient method.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
The Win32 API has integrated functionality that enables your application to wait until a shelled process has completed. To use these functions, you need to have a handle to the shelled process. To accomplish this, you need to use the CreateProcess() function instead of the Shell() function to begin your shelled program.
Below are the steps necessary to build a Visual Basic for Applications procedure that uses the CreateProcess() function to run the Windows Notepad (NOTEPAD.EXE) application. This code shows by example how to use the Windows API CreateProcess() and WaitForSingleObject() functions to wait until a shelled process ends before resuming execution.
The syntax of the CreateProcess() function is complex, so in the example code, it is encapsulated into a function called ExecCmd(). ExecCmd() takes one parameter, the command line of the application to execute.
For additional information about Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/226118/EN-US/ )OFF2000: Programming Resources for Visual Basic for Applications