注冊(cè) 登錄
Office中國論壇/Access中國論壇 返回首頁

tmtony的個(gè)人空間 http://ctxi.cn/?75 [收藏] [復(fù)制] [分享] [RSS]

日志

下面代碼判斷報(bào)表是否已被打。ú还芾硎穷A(yù)覽還是直接打。

熱度 7已有 4064 次閱讀2010-7-25 15:33 |個(gè)人分類:Access|

下面代碼判斷報(bào)表是否已被打。ú还芾硎穷A(yù)覽還是直接打。

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. 創(chuàng)建一個(gè)全局變量
Public intPrinted as Boolean

2. 在模塊中創(chuàng)建下面兩個(gè)函數(shù)


--------------------------------------------------------------------------------

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. 在打印預(yù)覽工具欄上創(chuàng)建新的打印按鈕
   或修改現(xiàn)有的打印按鈕
a. 將打印及打印預(yù)覽按鈕的 動(dòng)作改為  '=PrintDialog()'


4. 在報(bào)表的關(guān)閉事件中 On_Close 添加如下代碼
--------------------------------------------------------------------------------

     If intPrinted = True Then
         'Run code for when report was printed successfully
     End If

--------------------------------------------------------------------------------

 

5. 在窗體上要打印或預(yù)覽報(bào)表時(shí)使用如下代碼
--------------------------------------------------------------------------------

    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

剛表態(tài)過的朋友 (0 人)

發(fā)表評(píng)論 評(píng)論 (6 個(gè)評(píng)論)

回復(fù) yodong 2010-7-27 19:41
嘩,好東西!
回復(fù) lirong 2010-8-8 22:22
好東西謝謝分享
回復(fù) wang1950317 2010-8-13 21:42
謝謝分享!
回復(fù) ZHENGLIAN 2010-9-24 08:14
好東西就要支持才是!!!
回復(fù) 余方方 2011-3-17 10:15
謝謝分享
回復(fù) yanghua1900363 2011-8-27 09:44
謝謝 學(xué)習(xí)了!

facelist doodle 涂鴉板

您需要登錄后才可以評(píng)論 登錄 | 注冊(cè)

QQ|站長郵箱|小黑屋|手機(jī)版|Office中國/Access中國 ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2024-10-23 06:26 , Processed in 0.111356 second(s), 18 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回頂部