Printing Microsoft Access 2010 Reports from Visual Studio


The world of programming is a strange realm of uncertainties. Sometimes a need arises to do a task because "sloppy programmers" didn't consider all the facts, or "sloppy planning". I put these terms into quotation marks because these reasons remain open for discussion. Yes, there are times that these reasons are the main reason for problems in your code and programs, but not always. Sometimes it depends on the situation at hand and the resources at hand. As a programmer, you should be willing to take these challenges head-on and face them.

The reason I mention these facts is because today's program is one of those topics that usually gets frowned upon - which is a tad unfair. I will demonstrate with my article today, how to print a Microsoft Access 2010 report from within your C# or VB.NET program. This topic is usually the start of a discussion on decent reporting tools such as Crystal Reports etc. Face it, not every company will use Crystal Reports or another product, simply because of funding or hardware concerns. Enough rambling, Let's get started with our project...


Our design is simple, as illustrated in Figure 1

Our design
Figure 1 - Our design


Add a project Reference to Microsoft Access 14 Object Library. By clicking on Project, Add reference, select the COM tab, and scroll down to Microsoft Access Object library. Just a note, you could ( if you do not have Microsoft Office 2010 yet ) make use of the Microsoft Access 12 Object library for Office 2007. There should be no differences. With this project, I tested with both Microsoft Access 2007 and Microsoft Access 2010


Apart from adding the Project Reference to Microsoft Access, we need to be able to reference the Access code library through code as well, add the following namespace:


Imports Microsoft.Office.Interop.Access 'Import MS Access funtionalities, ADD PROJECT REFERENCE AS WELL


using objAccApp = Microsoft.Office.Interop.Access; //Import MS Access funtionalities, ADD PROJECT REFERENCE AS WELL

Already the succinct differences between VB.NET and C# is clearly visible. VB.NET follows a three step process here:

  1. VB.NET imports the Access library
  2. It creates an object from that library (which we will do next)
  3. Lastly, it instantiates that object so that we could use it

C# on the other doesn't work like that. With C# we directly make an object of the Access library, and then instantiate other objects from it.

Browse Button

Add the following code for your browse button:


    Private Sub btnARBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnARBrowse.Click

        Dim objAccApp As New Microsoft.Office.Interop.Access.Application() 'Instantiate Access Object

        objAccApp.Visible = False 'Do Not Display Access Window

        Dim strFileName As String = txtARSource.Text.Trim() 'File Name To Open

        Dim ofdAccReport As New OpenFileDialog() 'Create New Open File Dialog

        ofdAccReport.Filter = "Microsoft Access (*.accdb)|*.accdb)" 'Set File Filter For OFD

        If strFileName.Length > 0 Then 'If File Selected

            ofdAccReport.FileName = strFileName

        End If

        If ofdAccReport.ShowDialog() = DialogResult.Cancel Then 'If Cancelled


        End If

        txtARSource.Text = ofdAccReport.FileName 'Display File Name 

        lstARReports.Items.Clear() 'Erase Previous ListBox Items

        objAccApp.OpenCurrentDatabase(ofdAccReport.FileName, False, "") 'Open Selected Access Database

        If Not objAccApp.Visible = False Then 'Do Not Display access Window(s)

            objAccApp.Visible = False

        End If

        Dim strReportSQL As String = "SELECT [Name] FROM MSysObjects WHERE Type = -32764" 'Search All Access Reports

        Dim daoDB As dao.Database = objAccApp.CurrentDb() 'Open The Access Database

        Dim rsReports As dao.Recordset = daoDB.OpenRecordset(strReportSQL, Type.Missing, Type.Missing, Type.Missing) 'Find All Reports

        While Not rsReports.EOF

            lstARReports.Items.Add(rsReports.Fields(0).Value) 'Add Each Report Name To The ListBox

            rsReports.MoveNext() 'Continue

        End While

        rsReports.Close() 'Close All Objects



        rsReports = Nothing 'Release All Resources
        daoDB = Nothing
        objAccApp = Nothing

    End Sub


        private void btnARBrowse_Click(object sender, EventArgs e)
            string strFileName = txtARSource.Text.Trim(); //File Name To Open

            OpenFileDialog ofdAccReport = new OpenFileDialog(); //Create New Open File Dialog

            ofdAccReport.Filter = "Microsoft Access (*.accdb)|*.accdb)"; //Set File Filter For OFD

            if (strFileName.Length > 0) //If File Selected
                ofdAccReport.FileName = strFileName;


            if (ofdAccReport.ShowDialog() == DialogResult.Cancel) //If Cancelled


            txtARSource.Text = ofdAccReport.FileName; //Display File Name

            lstARReports.Items.Clear(); //Erase Previous ListBox Items

            objAccApp.Application app = new objAccApp.Application(); //Instantiate Access Object

            app.Visible = false; //Do Not Display Access Window

            app.OpenCurrentDatabase(ofdAccReport.FileName, false, ""); //Open Selected Access Database

            string strReportSQL = "SELECT [Name] FROM MSysObjects WHERE Type = -32764"; //Search All Access Reports

            dao.Database daoDB = app.CurrentDb(); //Open The Access Database

            dao.Recordset rsReports = daoDB.OpenRecordset(strReportSQL, Type.Missing, Type.Missing, Type.Missing); //Find All Reports

            while (!rsReports.EOF)

                lstARReports.Items.Add(rsReports.Fields[0].Value); //Add Each Report Name To The ListBox

                rsReports.MoveNext(); //Continue


            rsReports.Close(); //Close All Objects

            rsReports = null; //Release All Resources
            daoDB = null;
            app = null;


In this procedure we create a new OpenFileDialog and allow for file selection. Once a file has been selected, we place the name into our Source textbox. Now it gets interesting. To open the physical Microsoft Access file we do not make use of ADO.NET here, as we are making use of the Microsoft Access object Library's functionalities. We make use of the OpenCurrentDatabase method (inside the Access object library) to open the selected database.

To identify the report objects present in the Access database, we use an SQL statement searching through MSysObjects for type -32764 (which is the report objects). Inside a loop that loops through all the objects present in the database, we place each report name into a listbox.

Lastly, we just close all the Access objects and release all the memory resources.

If you were to run your project now, you'd be able to get a list of all reports inside your selected database.

Print Button

Add the following code behind your Print button:


    Private Sub btnARPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnARPrint.Click

        Dim objAccApp As New Microsoft.Office.Interop.Access.Application() 'Instantiate Access Application Object

        Dim strAccReport As String = lstARReports.SelectedItem.ToString() 'Get Selected ListBox Item

        objAccApp.OpenCurrentDatabase(txtARSource.Text.Trim(), False, "") 'Open Database

        If Not objAccApp.Visible = False Then 'Do Not Show Access Window(s)

            objAccApp.Visible = False

        End If

        objAccApp.Visible = False

        objAccApp.DoCmd.OpenReport(strAccReport, Microsoft.Office.Interop.Access.AcView.acViewPreview, Type.Missing, Type.Missing, AcWindowMode.acWindowNormal, Type.Missing) 'Open Selected Report

        objAccApp.DoCmd.PrintOut(AcPrintRange.acPrintAll, Type.Missing, Type.Missing, AcPrintQuality.acHigh, Type.Missing, Type.Missing) 'Print Report

        objAccApp.CloseCurrentDatabase() 'Close Database

        objAccApp = Nothing 'Release Resources

    End Sub


        private void btnARPrint_Click(object sender, EventArgs e)

            string strAccReport = lstARReports.SelectedItem.ToString(); //Get Selected ListBox Item

            objAccApp.Application app = new objAccApp.Application(); //Instantiate Access Application Object

            app.OpenCurrentDatabase(txtARSource.Text.Trim(), false, ""); //Open Database

            app.Visible = false; //Do Not Show Access Window(s)

            app.DoCmd.OpenReport(strAccReport, Microsoft.Office.Interop.Access.AcView.acViewPreview, Type.Missing, Type.Missing, objAccApp.AcWindowMode.acWindowNormal, Type.Missing); //Open Selected Report

            app.DoCmd.PrintOut(objAccApp.AcPrintRange.acPrintAll, Type.Missing, Type.Missing, objAccApp.AcPrintQuality.acHigh, Type.Missing, Type.Missing); //Print Report

            app.CloseCurrentDatabase(); //Close Database

            app = null; //Release Resources


We obtain the selected (in the list) report name and store it inside a variable named strAccReport. We again make use of the OpenCurrentDatabase method to open the selected database. Now, we make use of the DoCmd method to Open the selected report, and to Print the the report out on paper.

Not too complicated, hey? No.

If you were to run your application now, you'd be able to print out any selected report from your Access database. I am including both sample projects below, just in case you put a foot wrong somewhere.


There, I hope you enjoyed this article and learned from it. This just shows how much is actually possible in the world of programming. Until next time, cheers!

Related Articles



  • Very good example

    Posted by Jorge Par on 05/15/2016 09:31am

    Thanks for the example, following the code saves a lot of research time. The only problem is that the code is using DAO which applies to MsAccess 2007. Are you going to revise this for future viewers? Thanks anyway.

  • Thank you

    Posted by Akhtar on 03/29/2016 11:12pm

    I read your article it is amasing for me because I was searh many time for my problem to print report of Access 2010 now i can do this by the help of your codd. Thank you very much

  • Student

    Posted by Nancy on 01/24/2014 02:27pm

    Both in the downloaded version for C# and in my code, there is an error on: dao.Database daoDB = app.CurrentDB(); and dao.Recordset rsReports = daoDB.OpenRecordset(startReportSQL, Type.Missing, Type.Missing, Type.Missing): Error: The type or namespace name 'dao' could not be found (are you missing a using directive or an assembly reference?) Any help would be appreciated, thanks!

    • dao is not in Lower Case

      Posted by Ldjiba on 12/06/2016 04:49am

      Hi Nancy, I must put dao in upcase [DAO].

  • Brief post illustrates the unignorable details of chanel and ways it could actually threaten your site.

    Posted by emeseesip on 05/07/2013 03:24am

    The Biggest And Most Detailed nike E-book You Ever Witnessed Or Your Cash Back [url=]グッチ 財布[/url] Ok, astounding service. Your company got to go look at nike now while it's still available ! [url=]グッチ 長財布[/url] nike assists every one of us by including several unique features and options. This is a unvaluable item for any enthusiast of gucci. [url=]グッチ ショルダーバッグ[/url] Unbiased write-up divulges Unique fresh, new things surrounding nike that noone is covering. [url=]シャネル 財布[/url] Reason why not a soul is referfing to adidas and for that cause the thing one should engage in right now. [url=]chanel バッグ[/url] New queries about adidas resolved and in addition the reasons why you has got to review each and every phrase of this specific write up. [url=]chanel 財布[/url] The fundamental principles behind adidas for you to make full use of starting today.[url=]nike[/url] A way to understand every part there is to know around nike in Some basic steps.

  • Chemise Burberry

    Posted by Wrinalertiece on 04/30/2013 02:35am

    burberry femme pas cher Chemise Burberry Pas Cher sacoche burberry pas cher Chemise Burberry Femme [url=][/url] , sac burberry pas cher [url=][/url] , Burberry Pas Cher

  • Odd summary gives the simple truth on mizuno which experts state not very many customers know.

    Posted by icoppyapedcap on 04/25/2013 02:23pm

    NuwFlfFymTtf [url=]ナイキスニーカー[/url]SbkDpsYvnFtr [url=エアフォース1-c-14.html]ナイキ エアフォース[/url]XcxWyqYdcCbu [url=エアマックス-c-12.html]nike air max[/url]YxdNbmUvhRzx [url=エア-ジョーダン-c-13.html]ナイキランニング[/url]LtoZstPwoMna

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date