views:

41

answers:

3

I am using the Shell() function to execute an external application in MS Access. Shell() returns a task ID of the specific process that was started.

I need a way to check if that process is still running or if it has closed. I'm sure that I will need to do some sort of windows API call but I can't seem to find anything just now.

+1  A: 

Shell Tasklist (Description at http://technet.microsoft.com/en-us/library/bb491010.aspx) is a good way to do it manually. I'm not sure how you could interact with the list of PIDs by automation, though. That's a bit more difficult.

Tip: If you just want to kill a process, use Shell "TaskKill /F /IM ""excel.exe""" to kill all open instances of MS Excel. Or Shell "TaskKill /F /IM ""msaccess.exe""" to kill all open instances of MS Access (including the Access file that hosts your VBA script, unfortunately). This is how I end my standard issue Error Handler.

Edit

When you run it, you should something like: alt text

PowerUser
When I run TaskList at the command prompt it isn't found. Is this an external application that I need to download? I can't seem to find any reference to this in the documentation.
Icode4food
Odd. Well, that link I provided is to the official documentation for WinXP. Are you one of those lucky few to work in a company that has an OS younger than 7 years old?
PowerUser
I am running XP Home. Maybe it is a Pro app? That doesn't make much sense to me but that is all I can think of!
Icode4food
A: 

A similar question was answered here: http://stackoverflow.com/q/1439200/480767

wsware
+1  A: 

This is an Access FAQ, and it was answered years and years ago on the FAQ site for comp.databases.ms-access, http://mvps.org/access/.

API: Shell and Wait

David-W-Fenton