VB程序打印水晶报表的典型方法2

80酷酷网    80kuku.com

  程序|打印|水晶报表
描述:

  本文介绍另一种流行的一种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

 

  

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: