Access still running after loading comaddin (1 Viewer)

lution

Registered User.
Local time
Today, 05:49
Joined
Mar 21, 2007
Messages
114
I needed to write a comaddin to be able to read information from a web service for my Microsoft Access application. In my form_load() sub I have the following code to make sure the addin is loaded and it gets synched up with the controls on the form:

Code:
    With COMAddIns("myAddinName.Connect")
        ' Make sure the COM add-in is loaded.
        .Connect = True

        ' Hook up the desired objects.
        .Object.HookupControls Me.fillCitationsButton, Me.cmdCancel, Me.txtUserName, Me.txtPassword, Me.dbPath, Me.dbName, Me.dbPassword
    End With
Then I do the following when the form is closed:
Code:
Private Sub Form_Close()

    With COMAddIns("myAddinName.Connect")
        .Connect = False
    End With

End Sub
Within the addin I've commented out all the calls, other than synching with the controls on the form:

Code:
Public Sub HookupControls( _
     ByVal button As Access.CommandButton, _
     ByVal button2 As Access.CommandButton, _
     ByVal textBox2 As Access.TextBox, _
     ByVal textBox3 As Access.TextBox, _
     ByVal textBox4 As Access.TextBox, _
     ByVal textBox5 As Access.TextBox, _
     ByVal textBox6 As Access.TextBox)

        fillCitationsButton = button
        fillCitationsButton.OnClick = "[Event Procedure]"
        cmdCancel = button2

        txtUserName = textBox2
        txtPassword = textBox3
        dbPath = textBox4
        dbName = textBox5
        dbPassword = textBox6


    End Sub
This should be the only code called within the addin if I open the form and then turn right around and close it. If I run from devstudio 2008 in debug mode, Access starts and stops properly but if I run Access directly and open the form then exit Access, Access is still running. Could anyone point me into some things to look for or suggestions on what might be keeping Access running? If I comment out the code in the with/endwith section Access stops properly when I run it directly so I'm not sure what to look at next?

Thanks,
Lution
 

myvirtualme

New member
Local time
Today, 06:49
Joined
Nov 5, 2010
Messages
2
Lution,

Did you find a solution to this problem? I'm experiencing the same issue after building an Add-In using the code structure provided in the MS Access Web Services example. Everything works great other than the orphan MSACCESS.EXE process.

Appreciate any feedback / answers you may have found.

Thx,
Jeff
 

lution

Registered User.
Local time
Today, 05:49
Joined
Mar 21, 2007
Messages
114
Please have a look at the http://support.microsoft.com/default.aspx/kb/317109 which talks about the proper way to release the COM objects while automating Office applications. Took a bit of experimenting but I finally got it to clean up properly.

Good luck.
 

lution

Registered User.
Local time
Today, 05:49
Joined
Mar 21, 2007
Messages
114
Also, not sure if you are straight 32 or 64 but if you are going to work in a mixed environment you will need to compile 32 bit only. I have another post here on the forums with those details... I think.
 

myvirtualme

New member
Local time
Today, 06:49
Joined
Nov 5, 2010
Messages
2
Lution thanks for pointing in the right direction - as they say, there are 1000-ways of coding one solution...

The key breakthrough for me was the combination of "Marshal.ReleaseObject" and calling the garbage collector. Hopefully this will help others since it was many Google hours finding the combination. Thanks for your help once again!


Here's what I ended up doing in OnDisconnection:

PublicSub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection

IfNot addInInstance IsNothingThen
Do
If System.Runtime.InteropServices.Marshal.ReleaseComObject(addInInstance) = 0 Then
Exit Do
EndIf
Loop
EndIf

IfNot applicationObject IsNothingThen
Do
If System.Runtime.InteropServices.Marshal.ReleaseComObject(applicationObject) = 0 Then
Exit Do
EndIf
Loop
EndIf

Me.applicationObject = Nothing
translatePLSSButton = Nothing
' set variables to nothing
frmStateCode =
Nothing
frmMeridianCode = Nothing
frmTownship = Nothing
frmTownshipDir = Nothing
frmRange = Nothing
frmRangeDir = Nothing
frmSection = Nothing

GC.GetTotalMemory(False)
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.GetTotalMemory(True)

EndSub
 

Users who are viewing this thread

Top Bottom