Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing an external program

Status
Not open for further replies.

acarr2032

Programmer
Oct 4, 2004
18
0
0
US
I have an external app that is started in the first part of the code, I want it to shut down when it is done doing what it has to do:

Private Sub Dump_Data_Click()
Dim stAppName As String

stAppName = "O:\Warehouse\Scan\Scanpal 2\AG Utilities\232_read.exe"
Call Shell(stAppName, 1)

Dim stDocName As String

stDocName = "import"
DoCmd.RunMacro stDocName

Exit_Dump_Data_Click:
Exit Sub

Err_Dump_Data_Click:
MsgBox Err.Description
Resume Exit_Dump_Data_Click

End Sub

You can see in the beginning that it starts the external app called 232_read.exe, how can I end this (Close the external app)when the process is finished after running the macro?
 
Hi
You might be able to use SendKeys. For example this opens and closes Notepad
Code:
RetVal = Shell("Notepad.EXE", 1)
AppActivate RetVal
SendKeys "%(FX)", True
 
That didn't seem to work, I get the external programto run, the problem is getting that external program to close after the macro is done.

Dim stAppName As String

stAppName = "O:\Warehouse\Scan\Scanpal 2\AG Utilities\232_read.exe"
Call Shell(stAppName, 1)

Dim stDocName As String

stDocName = "import"
DoCmd.RunMacro stDocName
 
It was a faint hope. I thought if you changed this:
Call Shell(stAppName, 1)
To:
RetVal=Shell(stAppName, 1)
You could then use:
AppActivate RetVal
Then send whatever keys are generally used to close the program. [sadeyes]
 
Thanks for the help, I am a newbie, so I am looking for the (easy) button. :)
 
acarr,
There's no easy way to do this, unfortunately. However, there is a lot of code out there that google will bring up to do just that. For example, if you search on the API CreateProcess(), and use that to open the app (instead of shell), you'll have more control and can kill the process. Also, as I recall FindWindow() API can help find the window, but it's been years since I've used that and I can't remember if just having the window handle is enough to gracefully kill the program. Shell() returns the process ID, and there might be an api out there where you can use that to kill it.

I know that's getting way over and beyond what you wanted, but unless the program itself supports some sort of OLE, it's not going to be easy to go out there and kill running programs.
--Jim
 
Try the code on
It seems to do what you're after!

hth

Ben

----------------------------------------------
Ben O'Hara "Where are all the stupid people from...
...And how'd they get so dumb?"
rockband.gif
NoFX-The Decline
----------------------------------------------
Want to get great answers to your Tek-Tips questions? Have a look at F
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top