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

3

10

I am asking if it is possible to host a Microsoft Access form inside a .Net form.

No I haven't gone mad, we are maintaining a massive system written entirely in VBA by somebody who didn't know a lot of VBA attempting to use Microsoft Access as an IDE. It's basically thousands of lines of spaghetti code and while we would love to scrap it and start from scratch, this is not an option.

We are therefore trying to improve what is there, and in this particular scenario it would be really helpful if we could somehow host the Microsoft Access forms inside a .Net Windows Form as we can interact with the proprietary hardware from .Net much more effectively than we can from VB6.

We currently have a .Net application that runs on the computer alongside the many MS-Access databases that the users have open at any one time, and the .Net application interacts with these using MS Access Interop with varying degrees of success. This is because it uses form titles and filenames/locations to get a handle on the database to do what it needs to do, and also relies on the user not interfering/switching off the application/moving the databases to their desktops etc. It's a bit of a mess.

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?

Selfpossession answered 19/7, 2012 at 15:53 Comment(5)
It's a little like strapping rocket engines to the Hindenburg.Gibbosity
Are you even able to add a reference to Access in .NET? If so look at the object browser and see if there are any controls. I was able to add a reference named Access but no UI controls came with it.Mallorymallow
@CodeSlave Now there's an Idea!Selfpossession
@Blam Yes you can, if you are using NuGet, literally open up the add references dialogue box and search for Access, if not you need to do a bit of scrolling in the add references box to find Microsoft.Office.Interop.Access, 12.0 lets you work with 2007, 14.0 lets you work with 2010, 15.0 let's you work with 2013!Selfpossession
If you're hosting a form from the full version of Access, maybe. The runtime EULA prohibits you from using it for purposes other than database functionality and has branding requirements.Moncrief
M
3

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.

Moncrief answered 21/7, 2012 at 1:38 Comment(0)
U
3

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

Unmade answered 20/7, 2012 at 22:24 Comment(1)
We had the same idea for a legacy Access database, but the limitations on VBA and the like were too much for us. Not that the new functionality they added to help mitigate the loss of VBA functionality wasn't appropriate. Rather, there was too much VBA.Moncrief
M
3

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.

Moncrief answered 21/7, 2012 at 1:38 Comment(0)
B
1

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.

Biotite answered 12/4, 2018 at 10:26 Comment(2)
Roger, did you ever find a solution to the .NET forms as a MDI child?Morna
@Morna Sadly, not quite. Never to the point of integrating form menus, or behaving properly with the Ribbon.Biotite

© 2022 - 2024 — McMap. All rights reserved.