我想通过sql语句,让report的set report.datasource = recordset
那么datamember怎么设置。
因为使用数据环境时,sql语句查询里有一个变量要通过程序输入,但这里输入总是无效,又无法调试。所以想绕过数据环境,有没有例子啊?
另外,有的数据只想在第一页开头显示一下,以后不用显示,有的数据是象表格一样一页页显示,怎么做法?

解决方案 »

  1.   

    請留意以下代碼:另外你最后說的問題在水晶報表中可以設置實現你想要的效果Private Function Report_Prepare() As Boolean
    On Error GoTo ProcErr    Dim l_strSql As String
        Dim crAppl As CRAXDRT.Application    '定義一個CRAXDRT執行程序
        Dim crReport As CRAXDRT.Report        '定義一個CRAXDRT報表
        Dim l_rsData As ADODB.Recordset    Report_Prepare = False               
        l_strSql = CreateSql                
        If Len(Trim(l_strSql)) = 0 Then
            Screen.MousePointer = vbDefault
            GoTo ProcExit
        End If    Set l_rsData = New ADODB.Recordset     
        l_rsData.Open l_strSql, cnnSQLDB, adOpenStatic, adLockReadOnly, adCmdText 
        If Not l_rsData.EOF Then
            Set crAppl = New CRAXDRT.Application
            Set crReport = New CRAXDRT.Report
            Set crReport = crAppl.OpenReport(App.Path & IIf(Right(App.Path, 1) = "\", "", "\") & "report\test.rpt", 1)        '打開報表的位置及名稱
            crReport.Database.setDataSource l_rsData, 3, 1
            '指定報表的數据來源為ADO       crReport.ParameterFields.GetItemByName("Title").AddCurrentValue("標題")
                            
    ProcExit:
        If Not l_rsData Is Nothing Then
           If l_rsData.State = adStateOpen Then
               l_rsData.Close
           End If
           Set l_rsData = Nothing
        End If
        If Not crReport Is Nothing Then
           Set crReport = Nothing
        End If
        If Not crAppl Is Nothing Then
           Set crAppl = Nothing
        End If
       '關閉所有打開的對象
        Exit FunctionProcErr:
        If Not l_rsData Is Nothing Then
            If l_rsData.State = adStateOpen Then
                l_rsData.Close
            End If
            Set l_rsData = Nothing
        End If
        If Not crReport Is Nothing Then
            Set crReport = Nothing
        End If    If Not crAppl Is Nothing Then
            Set crAppl = Nothing
        End If
        Screen.MousePointer = vbDefault
        If Len(objLeoSystem.strErrorFunction) = 0 Then
            objLeoSystem.strErrorModule = mc_strModule
            objLeoSystem.strErrorFunction = "Function Report_Prepare"
        End If
        Err.Raise Err.NumberEnd Function