How to insert text to "Enter Parameter Value" dialog?
I'm trying to generate PDF from Access report. Report pop's up dialog "Enter Parameter Value". How I could fill it with C#? Is it even that 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.D开发者_JAVA百科oCmd.OutputTo(MsAccess.AcOutputObjectType.acOutputReport, reportName, MsAccess.Constants.acFormatPDF, PDFFile, Type.Missing, Type.Missing, Type.Missing);
app.CloseCurrentDatabase();
}
}
}
You could try changing the SQL behind the query the report is based on to include your criteria at runtime. Not sure how to do it through c# but this is how you could do it in native VBA so hopefully you can reverse engineer it from there
DBEngine(0)(0).QueryDefs("Query_report_is_based_on").SQL = “SELECT foo FROM tblBar WHERE foo=’Something’ ”
I created VB script in all excel files that outputs PDF upon opening certain report.
精彩评论