Solved

Cannot run access report from c#

Posted on 2007-04-04
5
549 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

706 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

17 Experts available now in Live!

Get 1:1 Help Now