Example of using Crystal Reports 9 (1)

xiaoxiao2021-03-06  22

'********************************************************** *************** '* Crystal Report Examples' * Applicable Version: 9.0 '* Producer: Ma Yahong' * Production Time: December 28th, 2004 * situation: This is a call mode in the crystal report software (RPT file) '* menu -> Project -> Quote-> Selection:' * 1, Crystal Reports 9 ActiveX Desion and Runtime Library '* 2, Crystal Reports 9 ActiveX DESIONER RUN TIME LIBRARY '* A lot of friends have this question: After the report shows that the data is not refreshed, the solution is as follows:' * 1, in the design interface of the report, the menu "-" "Options" "" Tab - "Save the" Save the data with the report "to save, then" * 2, call the report object's discardsavedata method "**************** ********************************************* OPTION EXPLICITDIM report As New CrystalReport1Dim wjfilesys As FileSystemObject 'FSO object for file operations Dim WithEvents CrSecRH As Section' report display area of ​​the object Dim capp As New CRAXDDRT.Application 'report collection object Dim carp As New CRAXDRT.Report' report report objects in the collection DIM CARSUBP AS New Craxdrt.Report 'Report Subjects Objects DIM PIC2 AS OleObject' Report Ole Object DIM MyTXT AS CRAXDRT.TEXTOBJECT 'Report Objects TEXTBOX Object

Private sub combo1_change () 'zoom in (zoom) CRVIEWER91.ZOOM (CINT (Combo1.Text)) End Sub

Private sub fascist1_click () 'Show you first crviewer91.ShowFirstPageEnd Sub

Private Sub Command10_Click () 'Print Report CRVIEWER91.PRINTREPORTEND SUB

Private sub command11_click () crviewer91.showclosebuttonend Sub

PRIVATE SUB Command2_Click () 'Refresh Report CRVIEWER91.REFRESHEND SUB

Private submmand3_click () display Previous crViewer91.showpreviouspageend submmmand4_click () "Show Next crviewer91.ShownextPagend Sub

Private Sub Command5_Click () 'last page CRViewer91.ShowLastPageEnd SubPrivate Sub Command6_Click ()' in the search report contents If (txtSearch.Text <> "") Then CRViewer91.SearchForText (txtSearch.Text) End If txtSearch.Text = " "END SUB

Private submmand7_click () imported PDF DIM MyExportFile As String MyExportFile = App.Path "/TEMP.PDF" if wjfilesys.fileexists (myexportfile) THEN

wjfilesys.DeleteFile (myExportFile) End If Report.ExportOptions.DiskFileName = myExportFile Report.ExportOptions.FormatType = crEFTPortableDocFormat Report.ExportOptions.DestinationType = crEDTDiskFile Report.ExportOptions.PDFExportAllPages = True Report.Export (False)

End Sub

Private submmand8_click () 'Export to Exceldim MyExportFile AS String MyExportFile = App.Path "/Temp.xls" if wjfilesys.fileexists (myexportfile) THEN

wjfilesys.DeleteFile (myExportFile) End If Report.ExportOptions.DiskFileName = myExportFile Report.ExportOptions.FormatType = crEFTExcel97 Report.ExportOptions.DestinationType = crEDTDiskFile Report.ExportOptions.PDFExportAllPages = True Report.Export (False)

End Sub

Private submmand9_click () 'Exports to Worddim MyExportFile As String MyExportFile = App.Path "/Temp.doc" if wjfilesys.fileexists (myexportfile) THEN

wjfilesys.DeleteFile (myExportFile) End If Report.ExportOptions.DiskFileName = myExportFile Report.ExportOptions.FormatType = crEFTWordForWindows Report.ExportOptions.DestinationType = crEDTDiskFile Report.ExportOptions.PDFExportAllPages = True Report.Export (False) End SubPrivate Sub Form_Load () Screen. MousePointer = vbHourglassDim cn As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim strsql As StringDim i As IntegerIf cn.State = adStateOpen Then cn.Close'SQL SERVER connection With cn.Provider = "sqloledb" .ConnectionString = "data source = Dd; Initial Catalog = DFD; User ID = SA; Password = aaa ". Link WITHEEND WITH'MDB connection method with cn.Provider =" microsoft.jet.oledb.4.0 ".connectionstring =" data source = " app.path "/TEST.MDB QERSIST Security Info = false" .Openend with

STRSQL = "Select * from casort" if rs.state = adstateopen dam.closewith rs.activeConnection = cn.cursorlocation = aduseclient.open Strsql, CN, AdoPENDYNAMIC, ADLOCKTIMISTICEND WITH

SET Carp = CAPP.OpenReport (App.Path "/Crystaltest.rpt") 'Reports Table Object SET CARSUBP = Carp.OpensUBReport ("MyHGYP")' Take Submount Object SET CRSECRH = Carp.sections ("PageHeadersECTION1") ' Report the header display area object set pic2 = carp.sections ("PageHeadersECTION1"). ReportObjects ("Picture1") 'Repends on the OLE object in the header display area set mytxt = CRSECRH.ReportObjects ("mytxt")

For i = 1 to carp.database.tables.count 'Sets the data source if carp.Database.tables.item (i) .name = "Carsort" thencarp.Database.tables (i) .setDataSource Rsend ifnextfor i = 1 To CARSUBP.DATABASE.TABLES.COUNT 'Set the data source for the sub-report if carp.database.tables.item (i) .name = "Carsort" thencarsubp.Database.tables (i) .SetDataSource Rsend ifxtscreen.mousepointer = VBHOURGLASS' a setting parameter manner carp.ParameterFields (1) .ClearCurrentValueAndRangecarp.ParameterFields (1) .AddCurrentValue ( "myhgyp") carp.ParameterFields (2) .ClearCurrentValueAndRangecarp.ParameterFields (2) .AddCurrentValue (CInt ( "3")) ' the second parameter setting manner carp.ParameterFields.GetItemByName ( "gg"). ClearCurrentValueAndRangecarp.ParameterFields.GetItemByName ( "gg"). AddCurrentValue ( "myh11" & vbCrLf & "-2gyp") carp.ParameterFields.GetItemByName ( "ff ") .ClearCurrentValueAndRangecarp.ParameterFields.GetItemByName (" ff "). AddCurrentValue (CInt (" 673 ")) carp.DiscardSavedDataCRViewer91.ReportSource = carpCRViewer91.ViewReportScreen.MousePointer = vbDefau ltCRViewer91.Zoom 100 '---------------------- Screen.MousePointer = vbDefaultSet wjfilesys = CreateObject ( "Scripting.FileSystemObject") End SubPrivate Sub CrSecRH_Format (ByVal pFormattingInfo As Object) 'Formatting the objects in the report header display area SET PIC2.FORMATTEDPICTURE = LoadPicture (app.path & "/tsconfig.bmp")' Changes The Pic in the report header mytxt.text, "## ## 年 ## 月 ## 日 ") 'Format TEXTBOX text display mode End Sub

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

New Post(0)