This problem has asked in many forums. But I have never found a satisfactory answer. Write below a solution 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, Date, '"& format (dtpicker1.value," YYYY-MM-DD ") &") = 0 and hospitalization = "& cbopatient.itemdata (cbopatient.listIndex) else sql =" SELECT * from n_ihbill where datediff d, date, ' "& 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 "No data!", Vbinformation exit sub?
SET RPT = PrintApp.OpenReport ("Cryliushui.rpt") Rpt.Database.setDataSource Rstliushui
Call ViewReport (RPT, "," Printing ") RSTLIUSHUI.CLOSE SET RSTLIUSHUI = Nothing This allows the program and the logical separation of the report. If you use a report designer. Compilers need to be compiled each time you change the report format. Customers can even change their report format themselves.