设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 5320|回复: 13
打印 上一主题 下一主题

[报表] 下面代码判断报表是否已被打印(不管理是预览还是直接打印)

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2008-11-24 10:29:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面代码判断报表是否已被打印(不管理是预览还是直接打印)

1. 创建一个全局变量
Public intPrinted as Boolean
2. 在模块中创建下面两个函数

--------------------------------------------------------------------------------
Public Function PrintDialog()
On Error GoTo err_Proc
'Opens windows print dialog box
'If fails to print or cancelled then goes to error message and does not set intPrinted flag
     DoCmd.RunCommand acCmdPrint
     intPrinted = True
     'Enable following line if you want report to close immediately after printing
'     DoCmd.Close acReport, Screen.ActiveReport.Name   
exit_Proc:
    Exit Function
err_Proc:
    Resume exit_Proc
End Function

Public Function PrintReport(stDocName as String, stLinkCriteria as string, intPreview as Integer)
On Error GoTo err_proc
   'stDocName = Name of report
   'stLinkCriteria = filter criteria
   'intPreview = 0 print directly to printer _
                     = 2 print preview
    'Clear printed flag
    intPrinted = False
    'Open report
    DoCmd.OpenReport stDocName , intPreview, , stLinkCriteria   
    if intPreview = 0 then
        intPrinted = True
        Debug.Print "Printed Successfully"   
    End if
exit_proc:
    Exit Function
err_proc:
    Debug.Print "Print Failed"   
    Resume exit_procEnd Function
End Function
--------------------------------------------------------------------------------

3. 在打印预览工具栏上创建新的打印按钮
   或修改现有的打印按钮
a. 将打印及打印预览按钮的 动作改为  '=PrintDialog()'

4. 在报表的关闭事件中 On_Close 添加如下代码
--------------------------------------------------------------------------------
     If intPrinted = True Then
         'Run code for when report was printed successfully
     End If
--------------------------------------------------------------------------------

5. 在窗体上要打印或预览报表时使用如下代码
--------------------------------------------------------------------------------
    PrintReport "ReportName",  "Criteria", intPreview
    'Check if report was printed
    '- The following lines of code are only needed if the report is printed directly (ie not previewed)
    ' if the intpreview is always set to 2  then the following lines can be deleted
    If intPreview = 0 then
        If intPrinted = True then
            'Run code for when report was printed successfully
        Else
            'Run code for when report was just previewed OR the print failed
        End If
    End If
--------------------------------------------------------------------------------

intPreview = 0 to print directly
intPreview = 2 to preview the report
Edited as requested by Bernie
Edited by: VanThienDinh on Tue Jul 29 6:23:49 EDT 2008.
翻译 : tmtony
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2008-11-24 11:16:25 | 只看该作者
坐个沙发
谢谢[:18]
3#
发表于 2008-11-24 11:49:35 | 只看该作者
板凳,学习了
4#
发表于 2009-2-3 23:20:05 | 只看该作者
谢谢,向领导学习是必须的!
5#
发表于 2009-4-9 12:19:58 | 只看该作者
谢谢你分享!
6#
发表于 2009-4-10 19:41:53 | 只看该作者
以后再学
7#
发表于 2009-4-29 04:41:26 | 只看该作者
thank you ,good luck to u !
8#
发表于 2009-7-9 15:49:29 | 只看该作者
好好学习,认真学习下!
9#
发表于 2009-10-7 03:28:57 | 只看该作者
谢谢分享,学习。
10#
发表于 2010-7-24 12:08:58 | 只看该作者
学习学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-9-20 15:45 , Processed in 0.205203 second(s), 43 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表