特别说明:例子功能要全面,能正常运行,随便弄个mdb数据库作例子吧:)
1.动态指定rpt报表文件的数据源,就是能带参数那种,比如日期在某段时间内的记录等等
2.rpt报表文件的分组汇总要有,就是sub total ,grand total之类
3.如何读取或者设置rpt文件上面那些label或者textfield的文字,如label1我要显示当前的日期等;如何指定某些字段显示在某些textfield上,比如这个textfield1我要显示的是select a from b.请将例子email到[email protected].关于给分,email收到例子后我运行正常.我将上这个版面,查看留言,然后给分.给分方法:最多给给我例子的2个人,每个人50,如果某个人的例子very ok.100奉送!

解决方案 »

  1.   

    首先建立ODBC数据源,我用的是MDB数据库,建立水晶报表文件,请参照本例,比较简单。Option Explicit
    Private Const ODBC_ADD_DSN = 1
    Private Const ODBC_CONFIG_DSN = 2
    Private Const ODBC_REMOVE_DSN = 3
    Private Const vbAPINull       As Long = 0&
    Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" (ByVal hwndParent As Long, ByVal fRequest As Long, ByVal lpszDriver As String, ByVal lpszAttributes As String) As LongPublic Function CreateDSN(ByVal sTPath As String, ByVal sTDsn As String) As Long
        Dim strDriver As String
        Dim strAttributes As String
        strDriver = "Microsoft Access Driver (*.mdb)"
        
    '    strAttributes = "SERVER=SomeServer" & Chr$(0)
        strAttributes = strAttributes & "DESCRIPTION=筑龙供应商管理" & Chr$(0)
        strAttributes = strAttributes & "DSN=" & sTDsn & Chr$(0)
        strAttributes = strAttributes & "DBQ=" & sTPath & Chr$(0)
        strAttributes = strAttributes & "UID=" & Chr$(0)
        strAttributes = strAttributes & "PWD=" & Chr$(0)
        CreateDSN = SQLConfigDataSource(0, ODBC_ADD_DSN, strDriver, strAttributes)
        
    End FunctionPrivate Sub Form_Load()
      If CreateDSN(App.Path & "\ZLGYSR.mdb", "ZLGYS") <> 0 Then
        
      End If
      Dim CRY As CRAXDRT.Report
      Dim CRYAT As CRAXDRT.Application
      
      Set CRYAT = New CRAXDRT.Application
      
      Set CRY = CRYAT.OpenReport(App.Path & "\CP91.rpt")
      CR91.ReportSource = CRY
      CR91.ViewReport
    '  CRY.PrintOut True
    End Sub
      

  2.   

    经过我的探索,已经可以实现用动态数据集显示报表了。
    但也对jadehong达人表示万分感谢,毕竟能热心回答问题的人太少了.
    给分
    jadehong大人,cr报表动态改变一个field的值怎么办呢?就比如一个form上面我放个textfield,我可以textfield1.text="xxx"来随时改变我的显示文本,在cr designer上面我该怎么办?这个field不一定是数据库里面的字段,因为我只想动态改变显示一些文本信息而已.