用 仅字段的方式就不用绑字数据库了,只需把查询的记录集作为数据源赋给水晶报表就行了,具体可以参考 阿泰的水晶报表博客,窗体代码大概如下(水晶报表),供参考
Private objCRApp As New CRAXDRT.Application '水晶报表应用程序对象
Private objCRReport As New CRAXDRT.Report '报表对象
Private Sub CRViewer91_PrintButtonClicked(UseDefault As Boolean)
Dim lngRet As Long
'不使用默认设置
UseDefault = False
'进行打印机设置
objCRReport.PrinterSetup Me.hwnd
'直接打印(注意True/False的设置,主要是为了控制前一对话框取消的情况)
objCRReport.PrintOutEx True
End Sub
Private Sub Form_Load()
Dim rst As New ADODB.Recordset
Dim props As CRAXDRT.ConnectionProperties '报表数据源参数集
Dim prop As CRAXDRT.ConnectionProperty '报表数据源参数
'--------------------------------------------------
'构建与定义的记录集对应的数据集结构来模拟一次数据库操作
'以下的操作可以替换成任意的过程,最终目的就是处理成一个记录集
'作为报表的数据来源
'--------------------------------------------------
Set rst = New ADODB.Recordset
rst.Open "pjrpt", db, adOpenKeyset, adLockOptimistic
'创建报表
'--------------------------------------------------
'加载报表模板
Set objCRReport = objCRApp.OpenReport(App.Path & "\PjRpt.rpt", 1)
'加载报表字段定义文件
Set props = objCRReport.Database.Tables(1).ConnectionProperties
For Each prop In props
If InStr(prop.Name, "Field Definition File") > 0 Then
prop.Value = App.Path & "\PjRpt.ttx" '字段定义文件 PjRpt.ttx
Exit For
End If
Next
Set props = Nothing