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