1

I am working on a Office COM Add-In to launch the Add-in application from MS Access. Add-in loading fine.

Now I need current db name at the plug-in class, so I use applicationObject.CurrentDb() to load db object and get db name from the object.

Below is the call at "OnConnection" method for getting currentDb.

After this, I close Access application by clicking "X" icon. But Access is not closing and have to force close from Task manager.

     public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
    applicationObject = (Access.Application) application;            
    currentDb1 = applicationObject.CurrentDb();

    if (currentDb1 != null)
    {
        System.Windows.Forms.MessageBox.Show("Current DB " + currentDb1.Name, "DB Name");
    }
 .....
}

If "applicationObject.CurrentDb()" is not called, Access close just fine.

Tried to close and null(empty) the application object at OnBeginShutdown. But the same result.

public void OnBeginShutdown(ref System.Array custom)
    {
        object omissing = System.Reflection.Missing.Value;
        System.Windows.Forms.MessageBox.Show("MyCOMAddin Add-in is unloading.");
        currentDb1 = null;
        applicationObject = null;
 }

Reference I use: https://learn.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/office-com-add-in-using-visual-c

karthik
  • 105
  • 2
  • 15
  • How does code know what the "CurrentDb" is? Not seeing code to quit app. Maybe `applicationObject.Quit`. In Access VBA, object variables would be set to Nothing, not Null. Don't know about C# objects. – June7 Mar 19 '22 at 19:56
  • Have you tried calling `Marshal.ReleaseComObject()` on the currentDb object? – Kostas K. Mar 20 '22 at 08:04
  • Thank you June7. I tried applicationObject.Quit. It was not working – karthik Mar 21 '22 at 10:28
  • 1
    Thank you very much Kostas K. Marshal.ReleaseComObject() on currentDb1 resolved the issue. – karthik Mar 21 '22 at 10:29

0 Answers0