MSAccess Addin causing unload problem

B

brettn

I am attempting to create an add-in for MSAccess with C#

Using the VS2005 shared add-in template, I cast the application object to
Microsoft.Office.Interop.Access.Application and use the CurrentProject
property to get the name of the currently open Access Project. All works fine
until I close MSAccess - it disappears but is not unloaded (still in task
list), and subsequent attempts to run MSAccess fail until the previous
process instance is cancelled.


// cast application object
applicationObject = (Access.Application)application;

// from add-in action (say button.onClick)
string str = applicationObject.CurrentProject.ToString();

if I don't use any of the 'project' or 'data' properties of the
applicationObject, MSaccess closes ok (adding command bars etc works fine),
but even though references to CurrentProject work ok (return correct values),
using them stops MSAccess from unloading.

I've seen other posts to newsgoups about this behaviour, but no resolution.

Any help appreciated.
 
B

brettn

ok, solved this one...

Need to declare each object as a new variable - compound statements like :

string str = applicationObject.CurrentProject.Name;

create hidden objects that do not have their reference count decremented
during the normal garbage collection process, preventing the app from closing.

Thank you to knowledge base article 317109
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top