Link to home
Start Free TrialLog in
Avatar of Delphinidae
Delphinidae

asked on

Cannot run access report from c#

I am trying to preview an Access report using C# 2003.  I have this code which runs, but it doesn't do anything.  What am I missing?  

The overall goal is to get the report to open, then print to PDF using the acrobat driver save and close.
So far the code is opening the databse (non displayable) but does nothing else from what I can see.

                  Access.Application oAccess = null;

                  oAccess = new Access.ApplicationClass();
                  // Open a database in exclusive mode:
                  oAccess.OpenCurrentDatabase(
                        "C:\\db\\PV3.mdb" //filepath
                        ,false //Exclusive
                        ,""
                        );


                        oAccess.DoCmd.OpenReport(
                  "test", //ReportName
                  Access.AcView.acViewPreview, //View
                  System.Reflection.Missing.Value, //FilterName
                  System.Reflection.Missing.Value //WhereCondition
                  ,Access.AcWindowMode.acDialog
                  ,""
                  );
            MessageBox.Show("opened");
Avatar of stevbe
stevbe

With the code you have now it is only opening the report in preview mode and doing nothing with it. So you wouldn't *see* anything unless you make access visible.

Not sure this has anything relevant but ... the access convention for passing argument values by name is ...

Argument:=Value

I'm not sure how translate that into C#.

another option would be to pass the arguments by position (to avoid the translation) and pass an empty string ("") for the *missing* arguments.

Let me see if I can fuind some code for printing to PDF, I am sure I have seen a question for that.

Steve
Avatar of Delphinidae

ASKER

The report is pulling from a SQL query in access.  What is happening is that the report does not display at all on my system.  This is what confuses me.  I would have thought the report should display in preview mode.
ASKER CERTIFIED SOLUTION
Avatar of stevbe
stevbe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
here are a couple of links for PDF printing Access reports...

how to set the printer to PDF Printer in Access 2002 ...
https://www.experts-exchange.com/questions/21218177/Covert-or-print-Access-report-to-PDF-format-and-put-the-output-pdf-files-to-a-specified-fold-Points-will-increase.html?


how to print to pdf by setting the default printer to pdf distiller, also link for cutepdf (fereewaere) which you can basically do the same thing.
https://www.experts-exchange.com/questions/21855703/How-do-you-print-directly-to-pdf-without-previewing-report-in-MS-Access-first.html
Thanks for your help... Next thing is to pass the pth to save the pdf file... This solved my initial question.   I just cannot believe I forgot to set visible to true.