Shabdar.org
Webshabdar.org
Placing images and text on a crystal report PDF Print E-mail
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

dim appl as craxdrt.application
dim rpt as craxdrt.report
dim withevents sect as craxdrt.section

' change section10 to name of the section where picture is displayed

private sub form_load()
    set appl=new craxdrt.applicaiton
    set rpt=appl.openreport(app.path & "\reportname.rpt")
    set sect=rpt.sections("Section10")
end sub

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.

private sub sect_format(..............)
    with sect.reportobjects
        .item("picture1").setolelocation .item("fldPath").value
end sub

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 Declaration
Dim 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

Comments
Add New Search
+/-
Write comment
Name:
Email:
 
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
Please input the anti-spam code that you can read in the image.