Is it possible to host a Microsoft Access form inside a .Net Windows form?

ぐ巨炮叔叔 提交于 2019-12-05 03:47:27

As a short aside, before we begin, if...

  • you're asking how to host just one single Access form without the application chrome; and
  • you're using the runtime version of Access

...you're running afoul of the Access Runtime EULA:

2. ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS.

...

ii. Distribution Requirements. For any Distributable Code you distribute, you must...

  • keep the status bar containing the statement "Powered by Microsoft Office Access" displayed in your user interface to be viewed by users at all times;

It might pay to read the EULA (it's not that long) just to see what you can and can't use the Access Runtime for.

Therefore, I am asking if it is possible to somehow host a Microsoft Access form inside a .Net Windows form, by maybe adding the form itself as a control or a subform, in a way that would give me direct access to all of the controls on the form from .Net?

You might want to invert the scenario: run your .NET code inside Access.

This basically entails creating a Shared Add-in in Visual Studio that Access can load and manipulate. From there you can wire up controls and events.

public void HookupControls(
   Access.CommandButtonClass button,
   Access.ListBoxClass listBox,
   Access.TextBoxClass textBox1,
   Access.TextBoxClass textBox2)
{
    fillProductsButton = button;
    fillProductsButton.Click += 
        new Access.DispCommandButtonEvents_ClickEventHandler(
        fillProductsButton_Click);
    fillProductsButton.OnClick = "[Event Procedure]";

    unitPriceTextBox = textBox1;
    quantityTextBox = textBox2;
}

It requires some co-operation from your Access application:

With COMAddIns("SharedAddIn.Connect")
    ''// Make sure the COM add-in is loaded.
    .Connect = True

    ''// Hook up the desired objects.
    .Object.HookupControls Me.fillProductsButton, Me.productsListBox, _
        Me.unitPriceTextBox, Me.quantityTextBox
End With

Disclaimer: I wanted to try this but in Visual Studio 2012 it seems the ability to create a Shared Add-in is missing. YMMV. There's references to Shared Add-ins in the documentation, however, so perhaps I'm missing something or the functionality isn't in VS 2012 RC.

The short answer is "yes" the long answer is "...but it might not be worth the trouble."

You can publish an Access database, including Forms and Reports through SharePoint. I have not actually done it but I researched the option for a project and we went another direction.

Details here: http://office.microsoft.com/en-us/sharepoint-online-enterprise-help/build-and-publish-an-access-database-to-sharepoint-HA102435342.aspx

and http://office.microsoft.com/en-us/access-help/introduction-to-integrating-data-between-access-and-a-sharepoint-site-HA010131463.aspx

I think you are coming at it from the wrong direction. It's possible to load a .NET runtime into the MS Access memory space. And load your custom .NET DLL(s) into that runtime space.

And with a properly defined C style DLL API layer you can propagate calls into and back from the .NET code.

I know this because I've done it.

It's a miserable pain to figure out the necessary parameters, etc, but once done it's fairly smooth as long as you don't want Unicode data passed around.

Now I'm migrating 150+ forms and 150+ reports across into .NET. In a couple of years I might get to scrap the Access side :)

Anyway, I ran across this because I'm now trying to figure out how to get the .NET forms to act as a proper MDI child inside Access, so back to hunting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!