Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-报表

[access报表]如何使用 VisualBasic 代码来排序和要打印两报告

时 间:2008-08-20 23:15:50
作 者:umvsoft整理   ID:43  城市:江阴
摘 要:如何使用 VisualBasic 代码来排序和要打印两报告
正 文:



本文适用于 MicrosoftAccess 数据库 (.mdb 或 .accdb) 以及在 MicrosoftAccess 项目 (.adp)。

moderate: 要求基本宏、 编码, 和互操作技能。

有关 Microsoft Access 2000 版本与本文, 请参阅 231805 (http://support.microsoft.com/kb/231805/EN-US/).
概要
本文介绍方法, 可用于排序和打印两报告。 此方法备用 DoCmd.SelectObject 和 DoCmd.PrintOut Visual Basic 方法之间两报告。 Microsoft 提供编程示例仅, 供图示不附带任何明示或暗示。 这包括, 但不仅限于, 适销性或用于特定目的适用性的暗示保证。 本文假定您已熟悉与正在演示编程语言以及工具来调试过程来创建和使用。 Microsoft 支持工程师可以帮助解释功能的特定过程, 但它们将会修改这些示例以提供添加功能或构建过程以满足特定要求。

回到顶端
更多信息
有时, 可能要打印某个报表的页 1 和然后 Collate 该页与其他报表的页 1。 打开报告和分别打印每页需要基础查询以每次运行。 一个替代方法是, 采用主 / 子报表中两个报表。

要排序并打印两报告并以测试结果, 请按照下列步骤:
1.    打开示例数据库 Northwind.mdb 或示例 Access 项目 NorthwindCS.adp。
2.    创建一个新模块, 然后键入或粘贴以下代码:

'***********************************
'Declarations section of the module
'***********************************
Option Explicit
'*********************************************************************
'NumPages is the number of pages in the largest report. If one report
'has fewer pages, the DoCmd.PrintOut statement for the smaller report
'runs correctly, and no additional pages are printed.
'*********************************************************************
Function CollateReports(NumPages, Rpt1 As String, Rpt2 As String)
    Dim MyPageNum As Integer

    'Set the page number loop and alternate printing the report pages.
    For MyPageNum = 1 To NumPages
        'NumPages is the number of pages to print.
        DoCmd.SelectObject acReport, Rpt1, True
        DoCmd.PrintOut acPages, MyPageNum, MyPageNum
        DoCmd.SelectObject acReport, Rpt2, True
        DoCmd.PrintOut acPages, MyPageNum, MyPageNum
    Next MyPageNum
End Function
                       

3.    要测试结果, 立即窗口中键入以下行, 然后按 ENTER 键:

? CollateReports(1, "Sales by Category", "Sales Totals by Amount")
                       

注意 MicrosoftAccess 从每个报表打印一页。

Access软件网QQ交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助