ADO record set and crystal report

zhaozj2021-02-16  48

When using a crystal report, it is often not very good to control, and finally use this ultimate trick. That is to use the data definition file (TTX) to transmit the obtained ADO recordset to the crystal report.

Typically, the crystal report is created from the physical database, but now there is 32-bit Active Data Driver - P2Smon.dll, crystal can be connected to a database in advance.

First, you need to create a TTX file, after entering the data source, after selecting the form,

Click the " " after " " to pop the data source form

At this point, we use the "New" button to create a new data definition file (TTX), the format is as follows

After saving, we open this text file, you will find the format of the TTX file, which is the TAB segmentation.

Then, we follow the old set of streets of the crystal report, the rest is to pass the recorder.

Below, we must declare the API that the ADO record set needs.

Public Declare Function Peopenengine LIB "crpe32.dll" () AS INTEGER

Public Declare Function PegeterRorcode Lib "crpe32.dll" AS Integer

Public Declare Function PeopenPrintJob Lib "crpe32.dll" (Byval Rptname As String) AS INTEGER

Public Declare Function Peutputtowindow Lib "crpe32.dll" (_

Byval PrintJob as integer, _

Byval Title As String, _

Byval Left as long, _

Byval Top as long, _

Byval width as long, _

Byval Height As long, _

Byval style as long, _

BYVAL PWINDOW AS Long AS Integer

Public Declare Function peutputtoprinter lib "crpe32.dll" (_

Byval PrintJob as integer, _

Byval NCOPIES AS INTEGER AS INTEGER

Public Declare Function PestartPrintJob LIB "crpe32.dll" (_

Byval PrintJob as integer, _

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 STRINGPUBLIC DECLARE FUNCTION SETACTIVEDASOSOURCE LIB "P2SMon.dll" (_

Byval PrintJob as integer, _

Byval Tablenum as integer, _

X as long

Finally, give the printed code of the report.

DIM JOB AS INTEGER

DIM HANDLE AS INTEGER

'Open the print engine

Handle = peponengine

'Crystal error handling

IF Handle = 0 THEN

ErrorNum = PegeterRrorcode (Handle)

Msgbox "Print Engine Error!"

MsgBox "Error Code:" & ErrorNum

END IF

'Open print job

Job = peopenprintjob (app.path & "/new.rpt")

'Crystal error handling

IF job = 0 THEN

ErrorNum = PegeterRrorcode (Job)

Msgbox "Open the job new.rpt failed!"

MsgBox "Error Code:" & ErrorNum

END IF

'Transfer the ADO record set to the crystal report, and the generation of Adorecordset is no longer said.

Handle = setActiveDataSource (Job, 0, Adors)

'Output to print preview window

Handle = peutputtowindow (job, "new.rpt", 0, 0, 520, 520, ws_maximize, 0)

'Direct output to the printer

Handle = peutputtoprinter (job, 1)

'Crystal error handling

IF Handle <> 0 THEN

Handle = pestartprintjob (job, true)

IF Handle <> 0 THEN

Msgbox "printing"

Else

ErrorNum = PegeterRrorcode (Job)

Msgbox "print failed!"

MsgBox "Error Code:" & ErrorNum

END IF

Else

ErrorNum = PegeterRrorcode (Job)

Msgbox "Unable to output to form or printer"

MsgBox "Error Code:" & ErrorNum

END IF

'Close the print job

PECLOSEPRINTJOB (JOB)

'Close the print engine

PECLOSEENGINE

I am using VB6 crystal report 8.5, I feel that this way is more flexible and solves the problem of crystal report replenishment.

转载请注明原文地址:https://www.9cbs.com/read-27492.html

New Post(0)