注册 登录
Office中国论坛/Access中国论坛 返回首页

tmtony的个人空间 http://www.office-cn.net/?75 [收藏] [复制] [分享] [RSS]

日志

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

热度 7已有 3963 次阅读2010-7-25 15:33 |个人分类:Access|

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

This method of determining if a report has been printed works for both previewed and directly printed reports;
It requires setting up a global variable and either amending the print preview menu or creating your own custom menu.

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

刚表态过的朋友 (0 人)

发表评论 评论 (6 个评论)

回复 yodong 2010-7-27 19:41
哗,好东西!
回复 lirong 2010-8-8 22:22
好东西谢谢分享
回复 wang1950317 2010-8-13 21:42
谢谢分享!
回复 ZHENGLIAN 2010-9-24 08:14
好东西就要支持才是!!!
回复 余方方 2011-3-17 10:15
谢谢分享
回复 yanghua1900363 2011-8-27 09:44
谢谢 学习了!

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

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

GMT+8, 2024-3-29 22:34 , Processed in 0.053975 second(s), 18 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部