Dynamic images in Crystal Reports .rpt

cltuser
10-22-2004, 05:16 AM
Is there anyway you can print images dynamically to a .rpt report created in crystal reports 8.5 developer using visual basic 6.0??? I have a report which is to display an image for each record in the database. My images are j-peg files stored in a folder on a server. I tried to use a Picture object from within Crystal Reports but it seems you can only give it one file name which displays the same picture on every record. Can this be done using a .rpt file and calling it from VB 6.0?? Any help would be greatly appreciated.

MKoslof
10-22-2004, 06:02 PM
If you have the developer's version of Crystal Reports ABSOLUTELY create an embedded .dsr object for your report, instead of a native .rpt file. The problem with dynamic images is that Crystal Reports evaluates its object on a section by section basis. With a native .rpt file, you don't have runtime access to the .rpt section events..so this is very troublesome.

If you use a .dsr you can code events via the .LoadPicture method in the section formatting events.

kelvinkoh
10-22-2004, 06:14 PM
Hi,

This is a bit out topic, but am a newbie in cyrstal report. Just wondering what is the embeded.dsr object you mentioned?

MKoslof
10-22-2004, 06:18 PM
If you are using the Developer's version of Crystal Reports, you have an option to created embedded Crystal Reports within your VB application. These embedded objects implement the standard Crystal Reports Engine API class, meaning they function just like standard .rpt files and they are compiled directly into your VB application.

Harkon
10-22-2004, 06:26 PM
Is there anyway you can print images dynamically to a .rpt report created in crystal reports 8.5 developer using visual basic 6.0??? I have a report which is to display an image for each record in the database. My images are j-peg files stored in a folder on a server. I tried to use a Picture object from within Crystal Reports but it seems you can only give it one file name which displays the same picture on every record. Can this be done using a .rpt file and calling it from VB 6.0?? Any help would be greatly appreciated.

also check this out.
I encountered the same issue.
http://www.xtremevbtalk.com/showthread.php?t=173342

I also resolved the same problem using .rpt instead of .dsr ( i dunno why but i dislike them). To do that you have to define the Details Section of your report in your project (using withevents to get the section methods). Something like Dim WithEvents Section5 as <i'm not quitesure of the name>.Section
Thus you could work as with the .dsr though you need to define everything from the beggining CRAXDRT.Appication, .DatabaseTables etc. which u don't have to when using the .dsrs

ps: i apologise for the innacurate_code response but I'm not home now and I don't have my files to browse. I shall do so when I return.

Regards

cltuser
10-24-2004, 04:31 PM
If you are using the Developer's version of Crystal Reports, you have an option to created embedded Crystal Reports within your VB application. These embedded objects implement the standard Crystal Reports Engine API class, meaning they function just like standard .rpt files and they are compiled directly into your VB application.

I added my .dsr and now I want to create a recordser to send to the report. I stuck right now. But this is what I've done so far. When this code is executed it give me all the data and not a sub-set. What am I doing wrong?? I want to select records in a range.

Set MyConn = New ADODB.Connection

MyConn.ConnectionString = DNSName
MyConn.Open
SQL = "SELECT * FROM BASE WHERE ACCOUNT_NO BETWEEN " & FirstPart & " And " & SecondPart
Set MyRecSet = MyConn.Execute(SQL)
'MyConn.Close
'Set MyConn = Nothing



'Get Values for all Heading fields

PropTitle = FrmUtilities.TxtPropHeading.Text
ClsTitle = FrmUtilities.TxtClsHeading.Text
StClsTitle = FrmUtilities.TxtStClsHeading.Text
RoutTitle = FrmUtilities.TxtRoutHeading.Text
AcctTitle = FrmUtilities.TxtAcctHeading.Text
ResValTitle = FrmUtilities.TxtResValHeading.Text
ComValTitle = FrmUtilities.TxtComValHeading.Text
MapBlkTitle = FrmUtilities.TxtMapBlkHeading.Text
ClientTitleName = FrmUtilities.TxtClientName.Text
Eff_DOV_Date = FrmUtilities.TxtEffDate.Text
If ParmsArray(4) = "1" Then
InspectionWitness = "1"
Else
InspectionWitness = "0"
End If


Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = Report


CrystalReport1.ParameterFields(1).SetCurrentValue PropTitle
CrystalReport1.ParameterFields(2).SetCurrentValue AcctTitle
CrystalReport1.ParameterFields(3).SetCurrentValue ClsTitle
CrystalReport1.ParameterFields(4).SetCurrentValue StClsTitle
CrystalReport1.ParameterFields(5).SetCurrentValue RoutTitle
CrystalReport1.ParameterFields(6).SetCurrentValue ResValTitle
CrystalReport1.ParameterFields(7).SetCurrentValue ComValTitle
CrystalReport1.ParameterFields(8).SetCurrentValue MapBlkTitle
CrystalReport1.ParameterFields(9).SetCurrentValue SecondPart
CrystalReport1.ParameterFields(10).SetCurrentValue FirstPart
CrystalReport1.ParameterFields(11).SetCurrentValue ReportKey
CrystalReport1.ParameterFields(12).SetCurrentValue TypeOfReport
CrystalReport1.ParameterFields(13).SetCurrentValue ClientTitleName
CrystalReport1.ParameterFields(14).SetCurrentValue Eff_DOV_Date
CrystalReport1.ParameterFields(15).SetCurrentValue InspectionWitness

If FrmMassPrt.TypeOfReport = "R" Or TypeOfReport = "C" Then
If ReportKey = "1" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.ACCOUNT_NO} in {?FirstPart} to {?SecondPart})"
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.ACCOUNT_NO} like {?FirstPart})"
End If
ElseIf ReportKey = "2" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.MAP_BLK_LOT} >= {?FirstPart} AND {BASE.MAP_BLK_LOT} <= {?SecondPart})"
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and {BASE.MAP_BLK_LOT} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "3" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.ROUTING_NO} >= {?FirstPart} AND {BASE.ROUTING_NO} <= {?SecondPart}) "
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and {BASE.ROUTING_NO} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "4" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.SORT_PROPERTY_LOC} >= {?FirstPart}) AND ({BASE.SORT_PROPERTY_LOC} <= {?SecondPart})"
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and {BASE.SORT_PROPERTY_LOC} LIKE {?FirstPart}"
End If
End If
Else
If ReportKey = "1" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.ACCOUNT_NO} in {?FirstPart} to {?SecondPart})"
Else
SelctFor = "({BASE.ACCOUNT_NO} like {?FirstPart})"
End If
ElseIf ReportKey = "2" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.MAP_BLK_LOT} >= {?FirstPart} AND {BASE.MAP_BLK_LOT} <= {?SecondPart})"
Else
SelctFor = "{BASE.MAP_BLK_LOT} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "3" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.ROUTING_NO} >= {?FirstPart} AND {BASE.ROUTING_NO} <= {?SecondPart}) "
Else
SelctFor = "({BASE.ROUTING_NO} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "4" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.SORT_PROPERTY_LOC} >= {?FirstPart}) AND ({BASE.SORT_PROPERTY_LOC} <= {?SecondPart})"
Else
SelctFor = "({BASE.SORT_PROPERTY_LOC} LIKE {?FirstPart})"
End If
End If
End If

Set Report = CrystalReport1

Report.RecordSelectionFormula = SelctFor
CRViewer1.ViewReport
Screen.MousePointer = vbDefault

Harkon
10-25-2004, 04:03 AM
please enclose your code in '[vb]' (starting and ending) tags so it is more readable.
thanxs

cltuser
10-25-2004, 01:57 PM
please enclose your code in '[vb]' (starting and ending) tags so it is more readable.
thanxs

Here is my code. Sorry about that all. I'm new so bear with me please

Private Sub Form_Load()
Dim SelctFor As String
Dim SQL As String
Dim TypeOfReport As String

Set Report = New CrystalReport1

PropTitle = FrmUtilities.TxtPropHeading.Text
ClsTitle = FrmUtilities.TxtClsHeading.Text
StClsTitle = FrmUtilities.TxtStClsHeading.Text
RoutTitle = FrmUtilities.TxtRoutHeading.Text
AcctTitle = FrmUtilities.TxtAcctHeading.Text
ResValTitle = FrmUtilities.TxtResValHeading.Text
ComValTitle = FrmUtilities.TxtComValHeading.Text
MapBlkTitle = FrmUtilities.TxtMapBlkHeading.Text
ClientTitleName = FrmUtilities.TxtClientName.Text
Eff_DOV_Date = FrmUtilities.TxtEffDate.Text
If ParmsArray(4) = "1" Then
InspectionWitness = "1"
Else
InspectionWitness = "0"
End If

If TypeOfReport = "R" Or TypeOfReport = "C" Then
If ReportKey = "1" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.ACCOUNT_NO} in {?FirstPart} to {?SecondPart})"
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.ACCOUNT_NO} like {?FirstPart})"
End If
ElseIf ReportKey = "2" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.MAP_BLK_LOT} >= {?FirstPart} AND {BASE.MAP_BLK_LOT} <= {?SecondPart})"
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and {BASE.MAP_BLK_LOT} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "3" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.ROUTING_NO} >= {?FirstPart} AND {BASE.ROUTING_NO} <= {?SecondPart}) "
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and {BASE.ROUTING_NO} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "4" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and ({BASE.SORT_PROPERTY_LOC} >= {?FirstPart}) AND ({BASE.SORT_PROPERTY_LOC} <= {?SecondPart})"
Else
SelctFor = "({BASE.LCI} = {?TypeOfReport}) and {BASE.SORT_PROPERTY_LOC} LIKE {?FirstPart}"
End If
End If
Else
If ReportKey = "1" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.ACCOUNT_NO} in {?FirstPart} to {?SecondPart})"
Else
SelctFor = "({BASE.ACCOUNT_NO} like {?FirstPart})"
End If
ElseIf ReportKey = "2" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.MAP_BLK_LOT} >= {?FirstPart} AND {BASE.MAP_BLK_LOT} <= {?SecondPart})"
Else
SelctFor = "{BASE.MAP_BLK_LOT} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "3" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.ROUTING_NO} >= {?FirstPart} AND {BASE.ROUTING_NO} <= {?SecondPart}) "
Else
SelctFor = "({BASE.ROUTING_NO} LIKE {?FirstPart}"
End If
ElseIf ReportKey = "4" Then
If FirstPart <> SecondPart Then
SelctFor = "({BASE.SORT_PROPERTY_LOC} >= {?FirstPart}) AND ({BASE.SORT_PROPERTY_LOC} <= {?SecondPart})"
Else
SelctFor = "({BASE.SORT_PROPERTY_LOC} LIKE {?FirstPart})"
End If
End If
End If

'MsgBox Report.RecordSelectionFormula
Report.DiscardSavedData
Report.RecordSelectionFormula = SelctFor
Report.ParameterFields(1).SetCurrentValue PropTitle
Report.ParameterFields(2).SetCurrentValue AcctTitle
Report.ParameterFields(3).SetCurrentValue ClsTitle
Report.ParameterFields(4).SetCurrentValue StClsTitle
Report.ParameterFields(5).SetCurrentValue RoutTitle
Report.ParameterFields(6).SetCurrentValue ResValTitle
Report.ParameterFields(7).SetCurrentValue ComValTitle
Report.ParameterFields(8).SetCurrentValue MapBlkTitle
Report.ParameterFields(9).SetCurrentValue SecondPart
Report.ParameterFields(10).SetCurrentValue FirstPart
Report.ParameterFields(11).SetCurrentValue ReportKey
Report.ParameterFields(12).SetCurrentValue TypeOfReport
Report.ParameterFields(13).SetCurrentValue ClientTitleName
Report.ParameterFields(14).SetCurrentValue Eff_DOV_Date
Report.ParameterFields(15).SetCurrentValue InspectionWitness
Report.Database.SetDataSource MyRecSet
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Me.Show
Screen.MousePointer = vbDefault

End Sub

When this is executed I still get prompted for my parameters. If I just click OK button no data is retrieved. If I enter data into my parm fields I get the correct results. I thought I was suppling the parameters with values prior to viewing the report. This works well when you use a .rpt but not a .dsr which is what I'm using.

Harkon
10-26-2004, 06:23 AM
do u mean you get your image as you want?
as for the promting try
'after opening the report object
Report.EnableParameterPrompting = False

cltuser
11-03-2004, 06:36 AM
If you have the developer's version of Crystal Reports ABSOLUTELY create an embedded .dsr object for your report, instead of a native .rpt file. The problem with dynamic images is that Crystal Reports evaluates its object on a section by section basis. With a native .rpt file, you don't have runtime access to the .rpt section events..so this is very troublesome.

If you use a .dsr you can code events via the .LoadPicture method in the section formatting events.MK I'm able to display one image but I have two images on the report. The report is a two page report. One image on page one and one on page two. Here is the code I'm using:

Private Sub Section5_Format(ByVal pFormattingInfo As Object)

PPNNumber = Me.Database.Tables.Item(1).Fields.Item(177).Value
CardNumber = Me.Database.Tables.Item(4).Fields.Item(91).Value
PictureFileName = Right$("000000" + Mid$(Str(PPNNumber), 2), 6) + Right$("00" + Mid$(Str(CardNumber), 2), 2) + ".jpg"
100 Set Picture2.FormattedPicture = LoadPicture(UniversDatPath + "PICTURE\" + PictureFileName)
Set Picture1.FormattedPicture = LoadPicture(UniversDatPath + "sketch\" + PictureFileName)

ErrorHandler:
If Err = 53 Then
PictureFileName = "NOAVAIL.jpg"
Err = 0
GoTo 100
End If

End Sub

One image is on the main report and the other is on a subreport within the main report. I get an error on PICTURE1.formattedpicture which is "PERMISSION DENIED" Error 70. When that line is executed.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum