我在datareport页注脚里添加了一个label控件有没有方法使label.caption属性每页显示的不一样呢?
比如我有a,b,c三个数值。我想第一页的label.caption=a,第二页的label.caption=b,第三页的label.caption=c。另:小弟我初来乍到,怎样给分?怎样看我最多有多少分可以给呢?

解决方案 »

  1.   

    Private Sub PageFooter_Format()
        Label.Caption = Choose(Me.pageNumber, "a", "b", "c")
    End Sub
      

  2.   

    谢谢 tiger 
    如果a,b,c是变量呢?
      

  3.   

    放在datareport 的代码中没反应阿
      

  4.   

    我是用 DataReport1.Show
    调用的
      

  5.   

    DataReport1内的代码,不是调用DataReport1.Show的地方。
      

  6.   

    我知道呀,我双击report放进去也不行。右键点击设计器里的report选查看代码放进去也不行。
      

  7.   

    你三页报表出来没有?该事件在每页结束是触发,用Debug.Print验证一下。
      

  8.   

    我本来是想在datareport里面做一个每页合计。但是能力有限,在网上找了半天也没找到。我就想在页注脚里面放一个label控件,再计算好每页的合计金额(因为每页都是固定行数),然后再每页改变label的caption属性。问题是我不知道怎样每页都改变caption属性。能实现么〉?
      

  9.   

    ActiveReport自带汇总功能。
    '在Footer上放一个字段,设置如下属性:
    .SummaryFunc=ddSFSum
    .SummaryDistinctField="金额" '需要汇总的字段名
    .SummaryRunning=ddSRAll
    .SummaryType=ddSMPageTotal '按页汇总
      

  10.   

    Tiger_Zhao 老兄14楼时说的代码是用activereport时用的吗?
      

  11.   

    给你一个datareport带页合计的示例,特别适合你每页固定行数的情况,是以前按别人要求写的:'=============================== DataReport报表示例 =================================='一.要求:查询数据库中内容,每页显示5行数据,有页合计。纸张规格 24.2cm * 11.60cm
    '二.分析:DataReport没有页合计功能,而且每页5行数据的设置比较困难,虽然可以通过调节
    '         边距来达到目的,但因系统、软硬件的设置,可能会在实际应用中出现偏差。要实现
    '     上述二项功能,分组是一个手段
    '三.思路:先导出表中数据,加上分组字段(5条数据一组)后导入一个新表。用ADO的SHAPE命令
    '         实现分组和统计。隐藏分组标头的信息,设置分组标头的ForcePageBreak = 1,实现
    '         每页5条数据的显示'====================================================================================='以下代码要选择“工程\引用”命令,引用“Microsoft AetiveX Date Objects 2.x Library”Option ExplicitPrivate Sub DataReport_Initialize()
        Dim cn As ADODB.Connection
        Dim rs As ADODB.Recordset
        Dim Sql As String, strSql As String
        Dim gID As Integer, i As Integer
        
        '连接数据库,打开记录集
        Set cn = New ADODB.Connection
        Set rs = New ADODB.Recordset
        
        cn.Provider = "MSDataShape"      '一定要这句,因为要用到ADO的SHAPE命令
        cn.Open "Data Provider=Microsoft.Jet.OLEDB.4.0; " _
            & "Data Source=" & App.Path & "\Northwind.mdb; " _
            & "Persist Security Info=False;" _
            & "Jet OLEDB:Database Password=zxcvbnm"
        rs.CursorLocation = adUseClient
        Sql = "select product,price,qty from tb"
        rs.Open Sql, cn, adOpenKeyset, adLockOptimistic
        
        '将信息添加分组字段导入临时表
        Sql = "delete from temp_tb"
        cn.Execute Sql              '先删除临时表中信息
        gID = 0
        For i = 0 To rs.RecordCount - 1
            If i Mod 5 = 0 Then gID = gID + 1    '5条信息用一个值,以便按gID分组
            Sql = "insert into temp_tb(group_id,product,price,qty) values " & _
                "(" & gID & ",'" & rs!product & "'," & rs!price & "," & rs!qty & ")"
            cn.Execute Sql
            rs.MoveNext
        Next
        Set rs = Nothing
        
        '用SHAPE命令打开分组父子记录集
        Sql = "select group_id,product,price,qty from temp_tb"
        strSql = "SHAPE {" & Sql & " } " & _
            "AS mGroup COMPUTE sum(mGroup.price) as price," & _
            "sum(mGroup.qty) as qty, mGroup BY 'group_id' "
        Set rs = New ADODB.Recordset
        rs.Open strSql, cn, adOpenStatic, adLockReadOnly
        
        '设置报表数据源
        Set Rpt.DataSource = rs
        '横向打印
        Rpt.Orientation = rptOrientLandscape
        
        '设置报表控件属性
            '分组标头,不用设置DataMember
        Rpt.Sections("Section6").Controls("text4").DataField = "group_id"
        Rpt.Sections("Section6").Controls("text4").Visible = False     '隐藏分组信息
        Rpt.Sections("Section6").ForcePageBreak = 1                    '强制分页
            '细节标头
        Rpt.Sections("Section1").Controls("text1").DataMember = "mGroup"
        Rpt.Sections("Section1").Controls("text1").DataField = "product"
        Rpt.Sections("Section1").Controls("text2").DataMember = "mGroup"
        Rpt.Sections("Section1").Controls("text2").DataField = "price"
        Rpt.Sections("Section1").Controls("text3").DataMember = "mGroup"
        Rpt.Sections("Section1").Controls("text3").DataField = "qty"
            '分组注脚,页合计。不用设置DataMember
        Rpt.Sections("Section7").Controls("text5").DataField = "price"
        Rpt.Sections("Section7").Controls("text6").DataField = "qty"
        Rpt.Sections("Section7").Controls("label1").Caption = "本页合计"
            '页标头,不要每页显示的话也可以放在报表标头中
        Rpt.Sections("Section2").Controls("Label2").Caption = "库存报表"
        Rpt.Sections("Section2").Controls("Label5").Caption = "报表日期:" & Date
        Rpt.Sections("Section2").Controls("Label7").Caption = "产品名称"
        Rpt.Sections("Section2").Controls("Label8").Caption = "价  格"
        Rpt.Sections("Section2").Controls("Label9").Caption = "库存数量"
            '页注脚
        Rpt.Sections("Section3").Controls("Label3").Caption = "制表:张三"
        Rpt.Sections("Section3").Controls("Label4").Caption = "审核:李四"
            '报表注脚总计信息:
        Rpt.Sections("Section5").Controls("Label6").Caption = "总  计"
        Rpt.Sections("Section5").Controls("Function1").DataField = "price"
        Rpt.Sections("Section5").Controls("Function2").DataField = "qty"
    End Sub
      

  12.   

    我14楼给的是ActiveReport 2.0的例子,其它报表也应该有类似的属性。