none
Create a Windows Forms application that can be referenced in a MS Access database

    Question

  • Hi everyone!

    Is it possible to make a Windows Forms application that you can reference in Microsoft Access (in the VBA code editor)? Basically I want to make a .NET Windows Form whose properties and methods can be accessed in much the same way as one would reference MS Excel, to wit:

    1. I create a .NET Windows Forms application in Visual Studio, compile it, and install it in my computer.

    2. In the same computer, I open MS Access (or any Microsoft Office program), and reference the .NET Windows Form.

    3. Still within Microsoft Access, I want to set the properties and access public methods of the Windows Form.

    4. I make the Windows Form visible to the user.

    Sunday, February 14, 2016 4:04 AM

Answers

  • One option could be to compile your windows form as a DLL with COM Interoperability

    In VS 2013

    1. Project Menu ->Properties
    2. Application -> Choose "Class Library" as the Output Type
    3. Click the Assembly Information button, make sure Assembly visible to COM is checked
    4. Under Build->check "Registr for COM Interoperability"
    5. Save project


    ....After you have compiled 

    1. Open your Access/VBA and add your DLL as reference (Tools->References->Browse)
    2. Navigate to your compiled project binary choose the tib file
    3. (you can have it show up automatically in references by using gasm to registry)

    As the function similar to this in the VBA macro

    Sub cmdTestLoadingDLL_Click()

    Dim obj As New WindowsFormsApplication1.Form1
    obj.show

    End Sub


    Sunday, February 14, 2016 9:04 AM