2012-07-05 98 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」。如果你覺得這有幫助,請投票