| Placing images and text on a crystal report |
|
|
|
| Written by Shabdar | ||
| Thursday, 05 February 2009 11:54 | ||
To place several images on a crystal report ' declare objects on the form where crystal viewer is
I cant recall what is the parameter name of the format event below, but when you declare section object WithEvents, as we did, then rpt object is shown in forms code window, just like any other control, so just as you would insert keypressevent for textbox, you can insert format event for section object.
picture1 is the name of the oleobject you inserted, and fldpath is the name of the table field where you have path to image, so you should change those two with correct names. Sample Code :'General DeclarationDim crxReport As CRAXDRT.Report Dim crxApplication As New CRAXDRT.Application Dim WithEvents Section3 As CRAXDRT.Section Dim rsTemp As New ADODB.Recordset Dim sSql As String Private Sub cmd_Report_Click() 'Open the Report Set crxApplication = New CRAXDRT.Application Set crxReport = crxApplication.OpenReport(App.Path & "\withphoto.rpt") 'Set Sectio3 to the Detail section of the report Set Section3 = crxReport.Sections(3) 'Discard saved data crxReport.DiscardSavedData ' asign the recordset to the report crxReport.Database.SetDataSource rsTemp, 3, 1 With frmView .Refresh .Caption = g_RptType & " Wise Report" .CRViewer1.ReportSource = crxReport .CRViewer1.ViewReport End With Screen.MousePointer = vbDefault Set rsTemp = Nothing Set crxApplication = Nothing Set crxReport = Nothing Set Section3 = Nothing Set rptObject = Nothing End Sub Private Sub section3_Format(ByVal pFormattingInfo As Object) Dim bmp As StdPicture With Section3.ReportObjects 'Check picture file exist or not using 'FileSystemObject.FileExists If Dir$(App.Path & "\images\" & .Item("Field9").Value) = Empty Then Set bmp = LoadPicture(App.Path & "\images\null.jpg") Else Set bmp = LoadPicture(App.Path & "\images\" & .Item("Field9").Value) End If Set .Item("Picture1").FormattedPicture = bmp End With Set bmp = Nothing End Sub ' end of the code 'THIS IS FOR REPORT VIEWER FORM '================================== 'Dim REPORT As New CrystalReport1 Dim Report As New CRAXDRT.Report Private Sub Form_Load() Screen.MousePointer = vbHourglass CRViewer1.ReportSource = Report CRViewer1.ViewReport Screen.MousePointer = vbDefault End Sub Private Sub Form_Resize() CRViewer1.Top = 0 CRViewer1.Left = 0 CRViewer1.Height = ScaleHeight CRViewer1.Width = ScaleWidth End Sub |