Launch Microsoft Access From C# Using Automation

First I am assuming that all you need to do is open an Access document from your C# application.  When you click a button or initiate a new event, you want to open an Access database in “Microsoft Access”.

Microsoft provides the following article but it is not complete http://support.microsoft.com/kb/317114.

Here are my steps after a lot of Googlings and swearings

1. First you have you have to add a reference to the Microsoft Access Objects

2. Second  you have to use the right namespace
using Access = Microsoft.Office.Interop.Access; 

3. Just modify the code below to fit your needs

        private void button1_Click(object sender, EventArgs e)
        {
            Access.Application oAccess = null;
            // Start a new instance of Access for Automation:
            oAccess = new Access.Application();

            // Open a database in exclusive mode:
            oAccess.OpenCurrentDatabase(@"c:\ycsoftware.mdb", true);
            oAccess.Visible = true;
        }

References
http://msdn.itags.org/visual-studio/8190/
http://support.microsoft.com/kb/317114

2 comments Write a comment