连接数据库With 数据环境.rsCommand名
If .State = adStateOpen Then .Close
.Source = SQL语句 
.Open 打开想输出的数据库数据项以便输出
End With
With 报表名
 .DataSource=数据环境
 .DataMember=Command名 这两行也可固定设好而不必每次设置
 设置页表头部分(RpttLabel…为报表控件名)
 .Sections(2).Controls("RptLabelPage").Caption = "共%P页第%p页"
 .Sections(2).Controls("RptLabelDate").Caption = "打印日期:%D"
 .Sections(3).Controls("RptLabel1").Left=…
 …
 设置细节部分(RptShapeX、RptTextBoxX为报表控件名)
 .Sections(3).Controls("RptShape1").Left=…
 .Sections(3).Controls("RptShape1").Top=…
 .Sections(3).Controls("RptShape1").Height=…
 .Sections(3).Controls("RptShape1").Width=…
 .Sections(3).Controls("RptTextBox1").DataMember=Command名
 .Sections(3).Controls("RptTextBox1").DataField=字段1
 .Sections(3).Controls("RptTextBox1").Font.Name=…
 …
 .Sections(3).Controls("RptShapeN").Visible=False
 .Sections(3).Controls("RptTextBoxN").Visible=False
 …
 . Sections(3).Height=计算出的或固定的细节高度
动态调整报表标题(RptLabelTitle为报表标签控件名)
 .Sections(2). Controls("RptLabelTitle").Left=…
 …
 .Sections(2). Controls("RptLabelTitle").Alignment=…
 …
 调整完毕后
 .Show 或 .PrintReport
End With谁能帮我把这段更具体化一些啊﹗谢谢了﹗

解决方案 »

  1.   


        DataEnvironment1.Commands("Command1").Parameters("p") = Text1.Text 
        DataReport1.Show这段语句应该放在哪里?
      

  2.   

    应该放在窗体中调用
    我是这样用的,deparam是数据环境,rptparam是报表
    deparm中的cmdparam的sql语句是Select * from orders where orderdate between ? and ?
    定义两个参数即可
    Private Sub cmdprint_Click()
       If deparam.rscmdparam.State = adStateOpen Then
          deparam.rscmdparam.Close
       End If
        deparam.cmdparam txtfrom, Txtto
        Load rptparam
        rptparam.Show
    End Sub
      

  3.   

    Private Sub cmdprint_Click()
       If deparam.rscmdparam.State = adStateOpen Then
          deparam.rscmdparam.Close
       End If
        deparam.cmdparam txtfrom, Txtto
        Load rptparam
        rptparam.Show
    End Sub