4. 创建VB程序
注意加入一个水晶报表控件(crystal report control)
一段最简单的程序:
例如:
Private Sub Command1_Click()
Dim iRet As Integer
CrystalReport1.Reset /*Reset Data*/
CrystalReport1.ReportFileName = App.Path + "\totalamount.rpt"
/*Link the Crystal Report Control with actual rpt file */
CrystalReport1.StoredProcParam(0)= Format(Trim$(DTPicker1.Value), "yyyy-mm-dd")
/*Assign the Parameter*/
CrystalReport1.WindowState = crptMaximized
CrystalReport1.WindowTitle = "HELLO"
iRet = CrystalReport1.PrintReport
/*Retrieve the Data and display the Printpreview Screen */
总结:
这个方法实现了水晶报表和VB程序的独立性,用户对于报表格式的改变将被局限于水晶报表的修改范围中. 建议大家采用这种方法.