** 描述 : **
本文介绍另一种流行的一种 VB 程序打印水晶报表的方法 .
环境 : MS SQL SERVER 2000 / VB6 / CRYSTAL REPORT8.5
步骤
1: 建立 ODBC 连接
2: 创建一个为 Crystal Report 报表文件
3: 加载 Microsoft ActiveX Data Objects Library 至项目的 References 中
4. 创建 VB 设计 (Designer) , 通过 open existing file 的方式把 Crystal Report 报表文件 加载进来 .
如果报表条件从画面输入需要写 一些简单程序 , 举例
Dim adoRs As ADODB.Recordset
Private Sub Report_Initialize()
SQL$ = "select * from view_XXXX where XXXX "
‘ 根据画面 , 重新获得 where 条件 ’
Set adoRs = CreateObject("adodb.recordset")
adoRs.Open SQL$, "Provider=MSDASQL.1;Persist Security Info=False;Data Source=odbc_sales", adOpenKeyset, adLockBatchOptimistic
Database.SetDataSource adoRs
End Sub
Private Sub Report_Terminate()
Set adoRs = Nothing
End Sub
5: 创建 VB 画面 (Form) , 加入 Crystal Report Viewer 控件
一些简单程序 , 举例
Dim RptReportName As Rpt_ReportName ‘RptReportName is name of designer
Private Sub Form_Load()
CRViewer1.ReportSource = RptReportName
CRViewer1.ViewReport
End Sub
**_ 总结 : _ **
**_ 这个方法实现了 VB 程序对水晶报表的控制 , 但是在可扩展性方面不如前一种有效 , 任何报表的格式改动 , 需要编译整个项目 L _ **