2012-07-05 97 views
0

我正在尝试使用Crystal报表(在VB应用程序中运行的Crystal XI)在尝试直接打印报表时收到零星“缺少参数值”错误的问题。这里的问题的总结:Crystal Reports XI PrintToPrinter“缺少参数值”

  1. 用户运行通过报告菜单报告(一切正常)
  2. 用户点击“打印预览”(一切正常)
  3. 用户点击“打印”(假设将文档直接发送到打印机,但有时会缺少参数错误)

以下是我对代码开始:

crystalReportViewer.MdiParent = parent 
    crystalReportViewer.Show() 

    Dim report As ReportDocument = CType(crystalReportViewer.ReportSource, ReportDocument) 

    report.PrintToPrinter(1, False, 0, 0) 
    crystalReportViewer.Close() 
    crystalReportViewer.Dispose() 

基于什么我已经google搜索,我想出了这个代码:

crystalReportViewer.MdiParent = parent 
    crystalReportViewer.Show() 

    Dim report As ReportDocument = CType(crystalReportViewer.ReportSource, ReportDocument) 

    'here are my attempts to get it to work 
    Dim pf As ParameterFields = report.ParameterFields 
    report.PrintOptions.PrinterName = "Microsoft XPS Document Writer" 

    report.PrintToPrinter(1, False, 0, 0) 
    crystalReportViewer.Close() 
    crystalReportViewer.Dispose() 

我对了对如何解决这个问题的想法。有没有其他人跑过这个?

+0

你能分享你得到的例外吗? – Asif 2012-07-06 05:00:55

+0

下面是错误的截图:http://tinypic.com/r/6tl84z/6 – lmg 2012-07-06 13:18:35

回答

0

据我所知,这在Crystal中看起来像一个问题。我无法找到修复程序,因此我只是在修复程序可用之前使用变通方法(生成报告并手动打印)。

1

开始代码:您可能在报告中有一些空的参数。

查询码后:你有这样一行:

Dim pf As ParameterFields = report.ParameterFields 

你有一个参数,而你没有设置任何价值。

对于这两种,使用方法:

//[C#] 
report.setParameterValue(parameterName, parameterValue); 
0

首先,你需要添加PrintDialog类工具箱 然后添加以下代码button_click_event

 ReportName.PrintOptions.PrinterName = PrintDialog1.PrinterSettings.PrinterName 

     ReportName.PrintOptions.PaperOrientation = CrystalDecisions.[Shared].PaperOrientation.Landscape 

     ReportName.PrintOptions.PrinterName = "Microsoft XPS Document Writer" 

     ReportName.PrintToPrinter(PrintDialog1.PrinterSettings.Copies, True, 1, 99) 

这将发送打印直接发送到“Microsoft XPS Document Writer”。如果你觉得这有帮助,请投票