Click to See Complete Forum and Search --> : Wait until external process is complete


CTdasDP01
October 19th, 1999, 04:50 PM
I am using visual basic for an application that searches an ODBC database for information and stores the information on an ms access database. From this application I shell open a word document and then Sendkeys() to merge the word doc with the data stored on the access database. I also send keys to close the document and bring the user back the VB application.

The problem arises when the application sends keys prematurely before Word is finished with its current process. Is there an API that can tell you when an external process is complete before continuing on with the executed code? I've tried using a timer but depending on how many documents will be merged requires more time or less. If there is not an API that does this effectively... Is there some other way??

Sky1000
October 19th, 1999, 06:16 PM
Yes, I've done it with C++ using the Win32 API, Instead of ShellExecute, use CreateProcess, it's a little more involved, but then once you've spawned the external executable you can call WaitForSingleObject, which will wait for the external process to complete ( it has a timeout parameter but it can be set to infinite). All the declares and such should be in the API Text Viewer.

Sky1000

Lothar Haensler
October 20th, 1999, 01:38 AM
IMHO if you want to control Word, you should use its automation interface. It's much more reliable and gives you much more control over Word's behavior.