2012-08-13 112 views
0

我知道我以前有過,但我不記得如何繞過它。Microsoft Access 2010託管代碼加載項 - 應用程序掛起

我構建了一個託管代碼加載項,除了一件事情之外,它還能正常工作。當我嘗試關閉Access應用程序時,應用程序窗口仍然存在,除非我結束任務。當我使用Visual Studio 2010調試外接程序時,它會在我停止調試時關閉。

我將所有變量設置爲斷開事件的一部分。

Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection 
    'On Error Resume Next 
    If Not MenuCommandControls Is Nothing Then MenuCommandControls.Delete() 
    If Not MenuCommandDimensionVariable Is Nothing Then MenuCommandDimensionVariable.Delete() 
    If Not MenuCommandFields Is Nothing Then MenuCommandFields.Delete() 
    If Not MenuCommandForms Is Nothing Then MenuCommandForms.Delete() 
    If Not MenuCommandParseSQL Is Nothing Then MenuCommandParseSQL.Delete() 
    If Not MenuCommandQueries Is Nothing Then MenuCommandQueries.Delete() 
    If Not MenuCommandReports Is Nothing Then MenuCommandReports.Delete() 
    If Not MenuCommandTables Is Nothing Then MenuCommandTables.Delete() 
    If Not MenuCommandVariables Is Nothing Then MenuCommandVariables.Delete() 
    If Not searchForm Is Nothing Then searchForm.Close() : searchForm = Nothing 
    If Not ObjectSetting Is Nothing Then ObjectSetting = Nothing 
    If Not AccessInst Is Nothing Then AccessInst = Nothing 
    If Not addInInstance Is Nothing Then addInInstance = Nothing 
    'If Not FormParseSQL Is Nothing Then FormParseSQL = Nothing 
    applicationObject.Quit(Access.AcQuitOption.acQuitPrompt) 
    If Not applicationObject Is Nothing Then applicationObject = Nothing 

End Sub 

回答

0

添加X爲可選整數子程序

創建退出應用程序按鈕, 設置X = 1 打電話給你的子程序,以及可選的X值傳遞給它。 把application.quit命令

在子程序的底部,如果x = 1 then application.quit。

通過退出應用程序按鈕調用ONdisconnect子例程。

禁用所有其他方式退出您的應用程序。

簡單,簡單和功能。

通過這種方式,當發生斷開連接或關閉應用程序時,Ondisconnect將工作。