お世話になっております。
【環境】
Windows XP Professional Service Pack 3
Visual Studio2005 VB.NET
Crystal Report2008 SP2
Oracle11G R2
【質問事項】
VB.NET2005からCrystal Report2008(SP2)を使ってレポートを発行したいのですが「プレビュー」がうまくいきません。
「印刷」はうまくいきます。
下記に記載したクラスのCrystalReportViewer1.ReportSource = Reportで値が渡せずエラーとなります。
エラーメッセージ:「指定されたキャストは有効ではありません。」
「CrystalReportViewer1」のフォームアイテムは、Crystal ActiveX Report Viewer Control 12.0を使用しています。
フォームが悪いのでは・・・と思いアイテムの追加にてCrystalReportViewerを使おうと思ったのですがエラーとなり
使用できませんでした。
エラーメッセージ:「コンポーネント'CrystalReportViewer'を生成できませんでした。」
どうしたらプレビューができるようになるのでしょうか?
原因、解決策等どなたかご教授願います。
以下現在のコードとなります。
-
Dim crReportDocument As CrystalDecisions.CrystalReports.Engine.ReportDocument
crReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim crTableLogOnInfo As New TableLogOnInfo
Dim i As Integer
listnam = PrgEnv & DIR_LPT & PRN_NAME ' 出力レポート名生成
crReportDocument.Load(listnam) ' プリントジョブナンバー取得
STRDEN = Format$(Val(txtText1(TXT1_STRDEN).Text), Txt1Fmt(TXT1_STRDEN))
ENDDEN = Format$(Val(txtText1(TXT1_ENDDEN).Text), Txt1Fmt(TXT1_ENDDEN))
SqlBuf = " ' " & STRDEN & " ~ " & ENDDEN & "'"
crReportDocument.DataDefinition.FormulaFields("SeL1").Text = SqlBuf
With crTableLogOnInfo.ConnectionInfo ' ログイン情報設定
.ServerName = SevNam
.UserID = UserID
.Password = UserPw ' パスワードセット
.IntegratedSecurity = False
End With
For i = 0 To crReportDocument.Database.Tables.Count - 1
crReportDocument.Database.Tables(i).ApplyLogOnInfo(crTableLogOnInfo)
Next i
crReportDocument.Database.Tables(0).Location = WrkVIEW
crReportDocument.Refresh()
Select Case PrnMode ' 印刷モード判定
Case PRN_PRN ' プリンター出力
crReportDocument.PrintToPrinter(1, True, 0, 0)
Case PRN_CRT ' 画面表示
Dim rptForm As New Crystal.Cyrstal(crReportDocument, PRN_CRT, LST_NAM) 'u2190クラスを以下に記載
rptForm.Show()
End Select
クラス 「Crystal」
Public Class Crystal
Inherits System.Windows.Forms.Form
Public Sub New(ByVal ReportName As ReportDocument, ByVal PrintMode As Integer, Optional ByVal ListName As String = "")
MyBase.New()
InitializeComponent()
ReportInit()
ReportShow(ReportName, PrintMode, ListName) 'レポートの印刷・表示を行う
Me.WindowState = FormWindowState.Maximized
End Sub
Public Sub ReportInit()
CrystalReportViewer1.Size = New System.Drawing.Size(1024, 738)
End Sub
Public Sub ReportShow(ByVal Report As ReportDocument, ByVal Print As String, ByVal ListName As String)
CrystalReportViewer1.DisplayGroupTree() = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
CrystalReportViewer1.ReportSource = Report u2190ココでエラーとなる
If Print = "1" Then
CrystalReportViewer1.PrintReport()
Else
Me.Text = ListName
End If
End Sub
-