用 VB6 開發程式很多年了,而 Crystal Report 也用了不少年(大概可以跟 VB6 差不多的使用時間吧),只是以前都是用 Crystal Report 6 在開發 Report。
整理了一下 Crystal Report 8 跟 9 在VB8 的語法
Dim crxApp As New CRAXDRT.Application '// 這些變數的宣告是都一樣的
Dim crxReport As New CRAXDRT.Report
Dim crxTable As CRAXDRT.DatabaseTable
Crystal Report 8
Set crxReport = crxApp.OpenReport("reportname.rpt") --> 報表名稱
crxReport.ParameterFields(1).AddCurrentValue aa_report_title --> 傳入CrystalReport Parameter
Set crxTable = crxReport.Database.Tables.Item(1) --> 下面這些 Crystal Report 8 與9 都一樣
crxTable.SetLogOnInfo "csmcsqt1", "csmcAA", "odbcsqluser", "csmcsqlusertest"
crxReport.RecordSelectionFormula = "{cos0002T.prog_id} = '" & Trim(x2s(Me.Name)) & "'" & _
" and {cos0002T.used_userid} = '" & Trim(x2s(SysNo)) & "'" --> 資料庫參數的傳送
crxReport.DiscardSavedData
Load CryRptFrm --> 開啟 Crystal Report 8 元件所在的 Form
CryRptFrm.CRViewer1.EnableNavigationControls = True
CryRptFrm.CRViewer1.DisplayGroupTree = True --> 開啟群組樹狀圖
CryRptFrm.CRViewer1.EnableExportButton = True
CryRptFrm.CRViewer1.EnableSearchControl = True
CryRptFrm.CRViewer1.ReportSource = crxReport
CryRptFrm.CRViewer1.EnableRefreshButton = False
CryRptFrm.CRViewer1.ViewReport
Crystal Report 9
crxReport.DiscardSavedData
crxReport.ParameterFields.GetItemByName(aa_report_title).AddCurrentValue aa_report_title
Load CryRptFrm
CryRptFrm.CRViewer91.EnableNavigationControls = True
CryRptFrm.CRViewer91.DisplayGroupTree = True
CryRptFrm.CRViewer91.EnableExportButton = True
CryRptFrm.CRViewer91.EnableSearchControl = True
CryRptFrm.CRViewer91.ReportSource = crxReport
CryRptFrm.CRViewer91.EnableRefreshButton = False
CryRptFrm.CRViewer91.ViewReport
'//呼叫完所有的物件請記得要把它清除乾淨喔
Set crxTable = Nothing
Set crxReport = Nothing
Set crxApp = Nothing
留言列表