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

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;


Let's share thisShare on Facebook
Tweet about this on Twitter
Share on LinkedIn

2 comments Write a comment

  1. i get error Microsoft office access cannot open database because it is missing or opened exclusively by another user

  2. 1. First of all make sure that the database really exists at the location you specified.
    2. Check to see if you do not have any lock files (.ldb)
    3. Replace  this statement:
    oAccess.OpenCurrentDatabase(@"c:\ycsoftware.mdb", true);
    oAccess.OpenCurrentDatabase(@"c:\ycsoftware.mdb", false);
    Chaging it to false indicates non-exclusivity.