Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2006, 07:17 PM
Authorized User
 
Join Date: Jul 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default end process in task mgr

I have a .mdb that creates a excel spreadsheet. The .mdb saves the spreadsheet and releases excel from memory.

appExcel.close 'close excel application
set appExcel to nothing 'releasing Excel application
set bks to nothing 'releasing the workbook
set wks to nothing 'releasing the worksheet

However, if you open the task mgr after running the script, I still see Excel.exe under the process tab. I have to manually select excel.exe in the task mgr and click end process.

If I dont do this and try tu run the script (in access) again, it error out. Is there another call to end this process programatically from access? Is it an API call?

 
Old September 29th, 2006, 06:44 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

You should check for the existence of the process at the beginning of each set of code for using the process, and if it is still running, kill the process first. I am sure that the posters here can show you a more elegant way, but here is the VBScript version that will run in your VBA:

Dim sComputer

sComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcesses
    If objProcess.Name = "EXCEL.EXE" Then
           WScript.Echo objProcess.Name
           errReturnCode = objProcess.Terminate()
       End If
Next

I have tested this and it works on a Windows XP box.

HTH

mmcdonal
 
Old September 29th, 2006, 06:46 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Sorry, I left in some error checking code. Here is the code you should use:

Dim sComputer

sComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcesses
    If objProcess.Name = "EXCEL.EXE" Then
           errReturnCode = objProcess.Terminate()
       End If
Next


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to hide a process in task manager ri_shu C++ Programming 3 October 25th, 2007 10:22 PM
end process in task mgr bab02 Access VBA 4 August 13th, 2007 04:30 PM
Oracle back-end MS-Access 2003 client front-end Corey Access 2 February 16th, 2007 08:31 AM
how to hide a process in task manager ri_shu Visual C++ 0 April 5th, 2006 07:33 AM
how to hide the process from the task-manager ri_shu VB How-To 0 April 5th, 2006 07:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.