description:
This article describes a method of printing a crystal report in popular VB programs with a better scalability.
surroundings:
MS SQL Server 2000 / VB6 / Crystal Report8.5
step
1: Establish an ODBC connection
2: Create a process of retrieving data for Crystal Report (Procedure)
Example: (Total query by date)
IF exists (Select * from sysobjects where name = 'usp_testfjs')
Drop Proc USP_Testfjs
Go
Create Proc USP_TestFJS
@Strdate Varchar (20)
AS
SELECT SUM (TOT_AMT) AS TOTAL_AMOUNT
From trans_header
WHERE Convert (VARCHAR (10), Bus_DT, 120) = @Strdate
Go
3. Create a Crystal report using ProCedure
Steps and create a general report, but pay attention to the Stored Procedures hook in Options when selecting the data source
4. Create a VB program Note Join a Crystal Report Control. For example: private submmand1_click () Dim IRet As Integer CrystalReport1.Reset / * Reset Data * / CrystalReport1.reportFileName = App.Path "/ TOTALAMOUNT.RPT" / * LINK The Crystal Report Control with actue RPT file * / crystalreport1.storedProcParam (0) = format (Trim $ (dtpicker1.value), "YYYY-MM-DD") / * Assign The parameter * / Crystalreport1.windowState = crptmaximized crystalreport1.windowtitle = "hello" IRet = CrystalReport1.printreport / * Retrieve the data and display the printpreview screen * /
Summary: This method realizes the independence of crystal reports and VB procedures, and users will be limited to the modification of the crystal report. It is recommended to use this method.