This project has moved and is read-only. For the latest updates, please go here.

Correct/best way to inherit from NetOffice.AccessApi.Form to use typed forms

Jul 23, 2014 at 11:01 AM
Edited Jul 23, 2014 at 11:43 AM
I want to use typed Forms inside an Access Addin. This allows access to controls with Intellisense and compile-time checks:
NetOffice.AccessApi.Form frm1 = Main.App.Forms("Customers");

CustomersForm frm2 = new CustomersForm(frm1.UnderlyingObject);
string dummy2 = frm2.CustomerID.Value.ToString;

CustomersForm frm3 = new CustomersForm(frm1);
string dummy3 = frm3.CustomerID.Value.ToString;
I get it work passing "Application.Forms" collection in constructor:
using NetOffice.AccessApi;

public class CustomersForm : NetOffice.AccessApi.Form
{

    public CustomersForm(NetOffice.AccessApi.Form frm)
    {
        base.New(Main.App.Forms, frm.UnderlyingObject);
    }

    public CustomersForm(object comProxy)
    {
        base.New(Main.App.Forms, comProxy);
    }

    public TextBox CustomerID {
        get { return (NetOffice.AccessApi.TextBox)this.Controls("CustomerID"); }
    }

    public TextBox CustomerName {
        get { return (NetOffice.AccessApi.TextBox)this.Controls("CustomerName"); }
    }

    public ComboBox CustomerCity {
        get { return (NetOffice.AccessApi.ComboBox)this.Controls("CustomerCity"); }
    }
    
}
, where "Main.App" is "Addin.Application" property.

I don't like to explicitly pass "Application.Forms" collection in constructor. But i didn't find how to use "ParentObject" argument of standard NetOffice.AccessApi.Form constructor.

As said, it's working. But i'm wondering if there are a better way to do this.

Any ideas?

Thanks.