打印本文 打印本文 关闭窗口 关闭窗口
ADO记录集和水晶报表
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1693  更新时间:2009/4/23 10:50:08  文章录入:mintao  责任编辑:mintao
;                  ByVal WaitOrNot As Integer) As Integer

                                                           

Public Declare Function PEClosePrintJob Lib "crpe32.dll" (ByVal printJob As Integer) As Integer

 

Public Declare Sub PECloseEngine Lib "crpe32.dll" ()

 

Public Declare Function CreateFieldDefFile Lib "p2smon.dll" ( _

                                                            lpUnk As Object, ByVal _

                                                            fileName As String, _

                                                            ByVal bOverWriteExistingFile As Long) As Long

       

Public Declare Function vbEncodelPtr Lib "p2smon.dll" (x As Object) As String

 

Public Declare Function SetActiveDataSource Lib "p2smon.dll" ( _

                                                                ByVal printJob As Integer, _

                                                                ByVal tableNum As Integer, _

                                                                x As Object) As Long

 

最后给出的是报表的打印代码

Dim Job As Integer

Dim Handle As Integer

''''打开打印引擎

Handle = PEOpenEngine

''''水晶的错误处理

If Handle = 0 Then

    ErrorNum = PEGetErrorCode(Handle)

    MsgBox "打印引擎出错!"

    MsgBox "错误代号:" & ErrorNum

End If

 

''''打开打印作业

Job = PEOpenPrintJob(App.Path & "\New.rpt")

''''水晶的错误处理

If Job = 0 Then

    ErrorNum = PEGetErrorCode(Job)

    MsgBox "打开作业New.rpt 失败!"

    MsgBox "错误代号:" & ErrorNum

End If

''''给水晶报表传送ADO记录集,AdoRecordset的生成就不再多说了

Handle = SetActiveDataSource(Job, 0, ADOrs)

''''输出到打印预览窗口

Handle = PEOutputToWindow(Job, "New.rpt", 0, 0, 520, 520, WS_MAXIMIZE, 0)

‘直接输出到打印机

Handle = PEOutputToPrinter(Job,1)

''''水晶的错误处理

If Handle <> 0 Then

Handle = PEStartPrintJob(Job, True)

    If Handle <> 0 Then

        MsgBox "打印完毕"

    Else

        ErrorNum = PEGetErrorCode(Job)

        MsgBox "打印失败!"

        MsgBox "错误代号:" & ErrorNum

    End If

Else

    ErrorNum = PEGetErrorCode(Job)

    MsgBox "无法输出到窗体或打印机"

    MsgBox "错误代号:" & ErrorNum

End If

''''关闭打印作业

PEClosePrintJob (Job)

''''关闭打印引擎

PECloseEngine

 

我使用的是VB6+水晶报表8.5,感觉这种方式比较灵活好用,同时解决了水晶报表补空行的问题。

上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口