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?
On the File tab, under Help, click Options. In the Access Options dialog box, click Current Database. Under Application Options, click Web Display Form, and then select the form that you want from the list. Note: You do not have to select your navigation form as the web display form.
If the form will be filled out by using a Web browser, the form cannot submit data directly to a database. To configure a browser-compatible form template to submit data to a database, use a data connection that submits data to a Web service that works with the database.
A split form gives you two views of the data at the same time — a Form view and a Datasheet view.
On the Design tab, in the Controls group, click the Subform/Subreport button. Click on the form where you want to place the subform. Follow the directions in the wizard. When you click Finish, Access adds a subform control to your form.
As a short aside, before we begin, if...
...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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With