高级报表
Access报表补空行代码
2017-06-05 16:57:32

Access报表存在先天的不足,一些复杂报表更加是无能为力。Access报表是不能直接自动创建表格的。那么在打印数据量少的时候,会有一片空白,我们这是就需要补空行去美观报表了。

1.分组不带签名栏的报表2.分组带签名栏的报表3.未分组带签名栏的报表4.未分组未带签名栏的报表 

详细源码:

'Private Const intCountPerPage = 20      ''是指定的每页打印记录行数

Public LngAllRecords As Long           ''统计节全部记录数

Public IntPageCount As Integer         ''页计数

Public LngSectionCount As Long         ''节计数

Public Sub SetDetailFormat(ByVal TheReport As Report, ByVal CountAllRows As Integer, Optional intCountPerPage As Integer = 20, Optional SectionSurplusRows As Integer = 0)

'===============================================================================

'-函数名称:         SelectDetailFormat

'-功能描述:         设置报表的不足补空行报表

'-输入参数说明:   参数1:TheReport             报表,输入me

'                   参数2:CountAllRows          统计所有的行

'                        请在报表上增加一个字段(例FieldsA),行来源为"=Count(*),可见性为否

'                   参数3:intCountPerPage       每页的行数

'                   参数4:SectionSurplusRows    分组剩余行给签名备注栏

'-返回参数说明:     无

'-使用语法示例:     SetDetailFormat me,me.FieldsA,20

'-参考:

'-使用注意:         请在报表的Report_Open事件中输入:TempRows=0 '初始化

'-兼容性:           2000,XP已测试

'-作者:             何勇, Email:Cuxun@qq.com  ,QQ:100810401

'-更新日期:        2007-9-21

'===============================================================================

    On Error GoTo Err:

'当有页面汇总时在页面页脚下相应减去节计数

'LngSectionCount = LngSectionCount - 1

    

    LngAllRecords = LngAllRecords + 1     ''全部的记录计数

    IntPageCount = IntPageCount + 1       ''页计数

    LngSectionCount = LngSectionCount + 1 ''节计数

    

    ''当每节的数据大于最大的数据,并且当页的行数小于每页最低行数时新加空白行

    If LngSectionCount >= CountAllRows And IntPageCount < intCountPerPage - SectionSurplusRows Then

    

       TheReport.NextRecord = False

    End If

    

    ''当页包含空行的数据等于最低行数时判断

    If IntPageCount Mod intCountPerPage = 0 Then

        ''分页

        TheReport.Section(0).ForceNewPage = 1

    Else

        ''不分页

        TheReport.Section(0).ForceNewPage = 0

    End If

    

    ''把前面的空行内的数据隐藏成白色

    If IntPageCount > CountAllRows Or LngSectionCount > CountAllRows Then

        showHideCtrlAtDetail TheReport, False

    Else

        showHideCtrlAtDetail TheReport, True

    End If

Err:

    ''不显示出错提示

'    If Err.Number <> 0 Then MsgBox Err.Description

    Exit Sub

End Sub

Private Sub showHideCtrlAtDetail(ByVal TheReport As Report, ByVal isShow As Boolean)

Dim Ctr1 As Control

''只针对主体页

    For Each Ctr1 In TheReport.Section(acDetail).Controls

        If isShow = False Then

            Ctr1.ForeColor = 16777215

        Else

            Ctr1.ForeColor = 0

        End If

    Next

End Sub

(报表设计-相关文章技巧链接):Access实现在报表最后一页列印空白表格线补满一页(补空行)