pass criteria to Ms Access report and print

megatronixs

Member
Joined
Jan 15, 2018
Messages
11
Programming Experience
Beginner
Hi all,

I was first trying to recreate all reports I had in Access database and print them from a Win form.
but this turned to be a lot of work and I'm quiet new to this C# coding and Win forms.

after some thinking and going trough google how to trigger the Access reports from C#, I found some nice code that does the trick.
The only catch for now that I have, I can't seem to be able to pass the criteria to the report.
The main form in the Access database has textbox that has the conn_ref in it. This is used to connect the report with the correct data when it opens up.

Any idea how to pass this via code to set the Master an Child connection?

This is the code I have so far:

C#:
using objAccApp = Microsoft.Office.Interop.Access;
 

        private void btn_print_Click(object sender, EventArgs e)
        {
            objAccApp.Application app = new objAccApp.Application(); //Instantiate Access Object
            app.OpenCurrentDatabase(@"//FeGrand/Shareddata/Tools/Feedback/Feedback.accdb", false, "");
            app.DoCmd.OutputTo(objAccApp.AcOutputObjectType.acOutputReport,
                "[Conn_Ref]=2923",//WhereCondition//ReportName
                "rptFax",
                ".pdf", //OutputType
                @"//FeGrand/Shareddata/Tools/Feedback/Test.pdf",  //outupuFile
                System.Reflection.Missing.Value,
                System.Reflection.Missing.Value,
                objAccApp.AcExportQuality.acExportQualityPrint
            );
            // cleanup
            app.CloseCurrentDatabase();
            app = null;
        }
        }

Greetings.
 
Back
Top Bottom