Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a kind of complex scenario

The Access-Application we are developing calls a VBA Function in another Access-Application which then triggers an Install Routine by calling the "calling" Access-Application. Both Applications are either accda (for Access-AddIn) or compiled accde files.

Admin.accda -> PlugIn.accda (InstallPlugIn) -> Admin.accda (RegisterPlugIn)

The corresponding line in Admin.accda looks like:

Application.Run("\\Path\To\PlugIn\PlugIn.InstallPlugin", "Parameters")

Everything works as expected except for one thing. Access keeps the file handle on the PlugIn.accda open until I close the Admin.accda.

When I debug my Code I can see that after calling Application.Run() in Admin.accda the VBA-Code of PlugIn.accda gets loaded into Admin.accda and a Lockfile for PlugIn.accda (PlugIn.laccda) gets created. When my code finishes the Lockfile has 0 Bytes but still exists.

By using the ProcessExplorer from Sysinternals I can see that the Process in which the Admin.accda is running still has a Filehandle open to the PlugIn.accda.

I want to close that file handle because there is nothing more to do with the PlugIn.accda and the open Filehandle could interfere with Process in the Clients Client/Server deployment like copying the PlugIn to the Client Computer.

Until now I have tried two different approaches but without success:

First: I tried to call the Run on Access-Application-Object and close that Object afterwards

  Dim oApplication As Object
  Set oApplication = CreateObject("Access.Application")
  oApplication.OpenCurrentDatabase Me.txtPathPlugIn
  If oApplication.Run("\\Path\To\PlugIn\PlugIn.InstallPlugin", "Params") Then
     'Do something
  End If
  oApplication.CloseCurrentDatabase
  Set oApplicaton = Nothing

With that approach the PlugIn was unable to call the RegisterPlugIn Function in the Admin.accda because it was exclusivly opened in another Process.

Second: I tried to close the PlugIn Database after the call to RegisterPlugIn in the Admin.accda by using:

CodeProject.CloseCurrentDatabase

But that had no effect what so ever :-(

Is there a way to close File handles by using some Windows-API functions? Or does anyone has an better approach to dynamically register additional Access files?

share|improve this question
Try calling 'oApplication.Quit' before you set 'oApplication' to nothing. See if that releases the handle for you. – Fink Mar 27 at 20:59

1 Answer

Maybe this is a dumb solution but just throwing it out there, you could use the taskkill command ? http://technet.microsoft.com/en-us/library/bb491009.aspx

share|improve this answer
+1 for "throwing it out there". I had to do something similar to kill "zombie" MSACCESS processes once, except that I used System.Diagnostics.Process.GetProcessById().Kill in a .NET app. – Gord Thompson Apr 4 at 22:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.