hell_tej 5 Junior Poster in Training

Hi, Frends
Now I m Telling You How to insert Image Dynemically in Crystal Report 8.5 for the use in VB 6:-/

I Create an Job placement Software Crystal Report Which has some Fields and Photo of Candidate so First I Create an Crystal Report in 8.5 then Save it as .rpt OK:cool:

Then i was Open Visual Basic 6.0 SP6 then Add Crystal Report from Project Explorer by Clicking Right button of mouse. Before Do that i was add the Report Components like Crystal Report Viewer from Controls, Crystal Report 8.5 from Designer and Crystal Report ActiveX control from Referances
:)
Then I was Create an blank Form and add Cristal Report Viewer to it. and Write some code as follows

Option Explicit
Dim cn As New ADODB.Connection
Dim rpt As CRAXDRT.Report
Dim db As CRAXDRT.Database
Dim rs As New ADODB.Recordset
Dim WithEvents sect As CRAXDRT.Section

'frmrpt2 for Candidate Bio -Data
Private Sub Form_Load()
If cn.State = 1 Then cn.Close
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\UJF\UJF.mdb;Persist Security Info=False"
Screen.MousePointer = vbHourglass
Set rpt = crx.OpenReport("D:\UJF\Retcomp.rpt")
Set db = rpt.Database
On Error GoTo solve
Set sect = rpt.Sections("Section5")
If rs.State = 1 Then rs.Close
rs.Open "SELECT * FROM biodata", cn, 1, 1
rpt.Database.SetDataSource rs, 3, 1
CRViewer1.ReportSource = rpt
CRViewer1.ViewReport
CRViewer1.Zoom 1
Screen.MousePointer = vbDefault
solve:
  If Err.Number = 445 Then
   On Error GoTo solve
   MsgBox "You Create an Crytical Manupletion", vbCritical
  End If
   
End Sub
Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub

Private Sub sect_Format(ByVal pFormattingInfo As Object)
Dim bmp As StdPicture
On Error Resume Next
With sect.ReportObjects
Set .Item("Picture1").FormattedPicture = LoadPicture("D:\UJF\ujf logo.JPG") 'default
If .Item("Field3").Value <> "" Then
Set bmp = LoadPicture(.Item("Field3").Value)
Set .Item("Picture1").FormattedPicture = bmp
End If
End With
End Sub

here Field 3 is the textbox which contain the path of JPG file form Access Database
Picture1 is the Picturebox to display picture
:zzz:
And DONE!!! I can See the Image Dynemicaly from Database...
:ooh:
STOP..........STOP.......STOP......STOP:angry:
Because it is not compleatly Currect for any Project or Software beccause
following Reason
:'( I Create another report like that which contain Dynemic IMAGE it also runs Fine but Error Occur When i Open Report after Update or Add andy New Record From The VB file
or Open Report more then two times or After opening First Report
I will Send you second Report(frmReport) Coading and other Module code

IF YOU ABLE TO FIND ERROR FROM THE CODE PLEASE SEND ME THE REPLAY

Option Explicit
Dim cn As New ADODB.Connection
Dim rpt As CRAXDRT.Report
Dim db As CRAXDRT.Database
Dim rs As New ADODB.Recordset
Dim WithEvents sect As CRAXDRT.Section
' frmReport For Giving Boi-data to Company
Private Sub Form_Load()
If cn.State = 1 Then cn.Close
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\UJF\UJF.mdb;Persist Security Info=False"

Screen.MousePointer = vbHourglass
Set rpt = crx.OpenReport("D:\UJF\Report1.rpt")
Set db = rpt.Database
On Error GoTo solve
Set sect = rpt.Sections("Section5")
If rs.State = 1 Then rs.Close
rs.Open "SELECT * FROM biodata", cn, 1, 1
rpt.Database.SetDataSource rs, 3, 1
CRViewer1.ReportSource = rpt
CRViewer1.ViewReport
CRViewer1.Zoom 1
Screen.MousePointer = vbDefault
solve:
  If Err.Number = 445 Then
   On Error GoTo solve
   MsgBox "You Create an Crytical Manupletion", vbCritical
  End If
End Sub
Private Sub Form_Resize()
CRViewer1.Top = 0
CRViewer1.Left = 0
CRViewer1.Height = ScaleHeight
CRViewer1.Width = ScaleWidth
End Sub

Private Sub sect_Format(ByVal pFormattingInfo As Object)
Dim bmp As StdPicture
On Error Resume Next
With sect.ReportObjects
Set .Item("Picture1").FormattedPicture = LoadPicture("D:\UJF\ujf logo.JPG") 'default
If .Item("Field3").Value <> "" Then
Set bmp = LoadPicture(.Item("Field3").Value)
Set .Item("Picture1").FormattedPicture = bmp
End If
End With
End Sub

Following Code is a module code which is used to astablish Connection to the Access Database

Option Explicit
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Public rs1 As New ADODB.Recordset

Public cn As ADODB.Connection
Public crx As New CRAXDRT.Application

Public Function OpenDatabase() As Boolean
On Error GoTo checkErr
Set cn = New ADODB.Connection
cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.ConnectionString = "Data Source=" & "D:\UJF\UJF.mdb"
'cn.Properties("Jet OLEDB:Database Password") = "yuMMy20" '|||||||if the password exist in database
cn.Open
OpenDatabase = True
Exit Function
checkErr:
MsgBox Err.Description, vbExclamation, Err.Number
End Function

Dani AI

Generated

Short checklist and fixes for — your idea (setting Picture1.FormattedPicture from the Field3 path in the Section.Format event) will work, but the crashes you see after updates / after opening a report repeatedly are classic symptoms of the Crystal runtime (CRAXDRT) or ADO objects not being released and/or the report viewer holding on to an old report instance. Two practical, low-risk options:

  1. Use Crystal's built‑in dynamic image support instead of LoadPicture. Insert a placeholder picture in the report, right‑click → Format Graphic → Picture tab → use the Graphic Location formula and point it to the path field (or a formula that builds the path). This avoids manual picture-loading code and is the most robust approach for dynamic images. (userapps.support.sap.com)

  2. If you keep the runtime approach, add a strict cleanup sequence every time you finish a report and before you open a new one (clear the viewer, close recordsets, close connections, unset event objects and rpt/crx references). Example (place in Unload or before opening another report):

Private Sub Form_Unload(Cancel As Integer)
  On Error Resume Next
  If Not CRViewer1.ReportSource Is Nothing Then CRViewer1.ReportSource = Nothing
  If rs.State = adStateOpen Then rs.Close
  If cn.State = adStateOpen Then cn.Close
  Set sect = Nothing
  Set rpt = Nothing
  Set crx = Nothing
  Set rs = Nothing
  Set cn = Nothing
End Sub

Always call DiscardSavedData / attach the correct ADO recordset with the appropriate SetDataSource usage and then show the report; examples and cleanup patterns are common in VB6 + CR code samples. Properly disposing objects avoids the GPFs / crashes many others have hit. (vbforums.com)

Troubleshooting tips: reproduce with a tiny test form that opens/closes the same report repeatedly and watch memory; add a Dir() or a Crystal formula that returns a default when the file path is missing (Graphic Location formula: If IsNull({biodata.Field3}) or {biodata.Field3} = "" Then "C:\default.jpg" Else {biodata.Field3} End If). Use UNC paths for network images and confirm file permissions. Also avoid always-declared-as-New module-level objects (prefer explicit Set ... = New and explicit Set ... = Nothing) to control lifecycle and avoid circular references. (community.sap.com)

If the problem persists after these changes, capture the exact VB error number and whether the crash happens on OpenReport, SetDataSource or when the viewer releases the report — that pinpoints whether the issue is image-loading, ADO/SetDataSource usage, or CR runtime cleanup.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.