日期:2011-04-14  浏览次数:20346 次

这个问题在很多论坛里边都有问到。但是一直没找到满意的答案。下边写出一个解决办法
Dim sql As String
Dim rstLiuShui As New ADODB.Recordset
Dim Rpt As New CRAXDDRT.Report
Dim PrintApp As New CRAXDDRT.Application
If Option2.Value = True Then
sql = "select * from n_ihbill where datediff(d,日期,'" & Format(DTPicker1.Value, "yyyy-MM-dd") & "')=0 and 住院号=" & cbopatient.ItemData(cbopatient.ListIndex)
Else
sql = "select * from n_ihbill where datediff(d,日期,'" & Format(DTPicker1.Value, "yyyy-MM-dd") & "')=0"
End If
Debug.Print sql

rstLiuShui.Open sql, adoconn, adOpenForwardOnly, adLockReadOnly

If rstLiuShui.EOF And rstLiuShui.BOF Then
MsgBox "没有可用数据!", vbInformation
Exit Sub
End If

Set Rpt = PrintApp.OpenReport("cryliushui.rpt")
Rpt.Database.SetDataSource rstLiuShui

Call viewReport(Rpt, "", "打印流水")
rstLiuShui.Close
Set rstLiuShui = Nothing
这样就可以实现程序与报表的逻辑分离。如果用报表设计器。每次更改报表格式都需要编译程序。客户甚至可以自己更改报表格式。