Solved

Cannot run access report from c#

Posted on 2007-04-04
5
552 Views
Last Modified: 2013-11-28
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");
0
Comment
Question by:Delphinidae
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:stevbe
ID: 18852536
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
0
 

Author Comment

by:Delphinidae
ID: 18852566
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.
0
 
LVL 39

Accepted Solution

by:
stevbe earned 250 total points
ID: 18852634
I think to see anything you are going to have to explicitly tell your access object to be visible

oAccess.Visible = True
0
 
LVL 39

Expert Comment

by:stevbe
ID: 18852639
here are a couple of links for PDF printing Access reports...

how to set the printer to PDF Printer in Access 2002 ...
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21218177.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.
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_21855703.html
0
 

Author Comment

by:Delphinidae
ID: 18852855
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.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now