I am injecting a piece of VBA code into a Microsoft Access database from .Net.
It is just a single line of code, which runs a Macro. All the Macro does is run a block of VBA code inside a module.
The issue I am having is that this all happens in a new MSAccess session, which I can’t even see, instead of the session the user currently has open.
Is it possible to, instead, have this interact with the users current MSAccess session? The whole point of this is to open a particular form inside the MSAccess session on every occurence of a .Net event. My C# code is below:
using Microsoft.Office.Interop.Access;
var msAccess = new Application();
msAccess.OpenCurrentDatabase(@"x:\foo\bar.accdb", false);
msAccess.DoCmd.RunMacro("macCTI");
msAccess.CloseCurrentDatabase();
Thanks
If you have a single instance of Access running you could use
Marshal.GetActiveObject:Alternatively, if more than one are running, and no two instances have the same database open, you could use
Marshal.BindToMoniker: