2010-08-31 74 views
0

我试图从Access报告中生成PDF。报告弹出的对话框“输入参数值”。我如何用C#填充它?它甚至是reportParameter(whereCondition)?如何在“输入参数值”对话框中插入文本?

using System; 
using MsAccess = Microsoft.Office.Interop.Access; 

namespace mdb2pdf 
{ 
    class Program 
    { 
     public static void Main(string[] args) 
     { 
      string MDBFile = @"d:\example.mdb"; 
      string PDFFile = @"d:\example.pdf"; 
      string reportName = @"myReport"; 
      string reportParameter = @"[Name?] LIKE 'myName'"; 

      MsAccess.Application app = new MsAccess.Application(); 

      app.OpenCurrentDatabase(MDBFile, false, ""); 
      app.DoCmd.OpenReport(reportName, Microsoft.Office.Interop.Access.AcView.acViewPreview, Type.Missing, reportParameter, MsAccess.AcWindowMode.acWindowNormal, Type.Missing); 

      app.DoCmd.OutputTo(MsAccess.AcOutputObjectType.acOutputReport, reportName, MsAccess.Constants.acFormatPDF, PDFFile, Type.Missing, Type.Missing, Type.Missing); 
      app.CloseCurrentDatabase(); 
     } 
    } 
} 

回答

0

我创建VB脚本中的所有Excel中,在打开某些报告输出PDF文件。

0

您可以尝试更改报表所依据的查询后面的SQL,以便在运行时包含您的条件。不知道如何做到这一点,通过C#,但这是你如何能做到这一点在本机VBA所以希望可以扭转从那里工程师它

DBEngine(0)(0).QueryDefs("Query_report_is_based_on").SQL = “SELECT foo FROM tblBar WHERE foo=’Something’ ” 
+0

为什么不把标准参数传递给OpenReport,而不必担心参数化SQL呢? – 2010-09-01 03:30:33

相关问题