dhamijap
asked on
Crystal Report 8.5 and VB6 changing picture in vb code
Hi:
I have vb 6 and crystal report 8.5. I am using MS Access databse. I created a report with 2 parameters to filter the records using parameters in CR. Now when I can view the reprot I need to add a picture in the report. The picture's path is a field in the table or I can also concatnate it in vb.
I need some one to give me example code to dynamically change the picture in the report. Also I need to print it directly without seeing it. So, my question has two parts. Points will be devided if two experts give me the answer one part each. I have made this to be 100 points. If it gets lengthy I will increase the points.
here is some of the code I am using.
Option Explicit
Dim CrApp As CRAXDRT.Application
Dim CrReport As CRAXDRT.Report
Dim CrParamDefs As CRAXDRT.ParameterFieldDefi nitions
Dim CrParamDef As CRAXDRT.ParameterFieldDefi nition '
Private Sub Form_Load()
Set CrApp = New CRAXDRT.Application
Set CrReport = CrApp.OpenReport("MyReport Name.rpt")
crReportViewer.Top = 0
crReportViewer.Left = 0
crReportViewer.Width = Me.ScaleWidth
crReportViewer.Height = Me.ScaleHeight
CrReport.ParameterFields.G etItemByNa me("pPID") .AddCurren tValue 11111
CrReport.ParameterFields.G etItemByNa me("pUID") .AddCurren tValue 'A'
crReportViewer.ReportSourc e = CrReport
CrReport.ReadRecords
crReportViewer.ViewReport
.
.
.
Thanks
I have vb 6 and crystal report 8.5. I am using MS Access databse. I created a report with 2 parameters to filter the records using parameters in CR. Now when I can view the reprot I need to add a picture in the report. The picture's path is a field in the table or I can also concatnate it in vb.
I need some one to give me example code to dynamically change the picture in the report. Also I need to print it directly without seeing it. So, my question has two parts. Points will be devided if two experts give me the answer one part each. I have made this to be 100 points. If it gets lengthy I will increase the points.
here is some of the code I am using.
Option Explicit
Dim CrApp As CRAXDRT.Application
Dim CrReport As CRAXDRT.Report
Dim CrParamDefs As CRAXDRT.ParameterFieldDefi
Dim CrParamDef As CRAXDRT.ParameterFieldDefi
Private Sub Form_Load()
Set CrApp = New CRAXDRT.Application
Set CrReport = CrApp.OpenReport("MyReport
crReportViewer.Top = 0
crReportViewer.Left = 0
crReportViewer.Width = Me.ScaleWidth
crReportViewer.Height = Me.ScaleHeight
CrReport.ParameterFields.G
CrReport.ParameterFields.G
crReportViewer.ReportSourc
CrReport.ReadRecords
crReportViewer.ViewReport
.
.
.
Thanks
ASKER
Gary:
So, I cant change the picture in 8.5 CR. That is the ans for q 1. what about printing it without viewing.
I will at least wait a day to see if someone else has an ans for part 1 of my q.
thanks
paul
So, I cant change the picture in 8.5 CR. That is the ans for q 1. what about printing it without viewing.
I will at least wait a day to see if someone else has an ans for part 1 of my q.
thanks
paul
Try
CrReport.PrintReport False
mlmcc
CrReport.PrintReport False
mlmcc
Check this link for changing an imge at runtime in CR8
http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=http--supportbusinessobjectscom-communityCS-FilesandUpdatesNoNav-scr8vbrdcchangeimagesexeasp&sliceId=&dialogID=14974886&stateId=1%200%2014978598
mlmcc
http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=http--supportbusinessobjectscom-communityCS-FilesandUpdatesNoNav-scr8vbrdcchangeimagesexeasp&sliceId=&dialogID=14974886&stateId=1%200%2014978598
mlmcc
A sample application to print to the printer using the RDC
http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=http--supportbusinessobjectscom-communityCS-FilesandUpdatesNoNav-crprintfromexplorerexeasp&sliceId=&dialogID=14974920&stateId=1%200%2014978646
mlmcc
http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=http--supportbusinessobjectscom-communityCS-FilesandUpdatesNoNav-crprintfromexplorerexeasp&sliceId=&dialogID=14974920&stateId=1%200%2014978646
mlmcc
ASKER
mlmcc:
in the first link when I look at the code it is refering to a bmp picture. I have jpg would it work with jpg or not?
paul
in the first link when I look at the code it is refering to a bmp picture. I have jpg would it work with jpg or not?
paul
You can try. CR8 and 8.5 had limited picture capability.
mlmcc
mlmcc
ASKER
mlmcc:
using this link
http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=http--supportbusinessobjectscom-communityCS-FilesandUpdatesNoNav-scr8vbrdcchangeimagesexeasp&sliceId=&dialogID=14974886&stateId=1%200%2014978598
and looking a tthe code, I am getting an error on: "OpenReport" at the line below in Form_load
Set Report = Appl.OpenReport("K:\DCMS\R eports\" & "pic.rpt", 1)
I am not sure what is going on. Can you help me there.
p
using this link
http://technicalsupport.businessobjects.com/KanisaSupportSite/search.do?cmd=displayKC&docType=kc&externalId=http--supportbusinessobjectscom-communityCS-FilesandUpdatesNoNav-scr8vbrdcchangeimagesexeasp&sliceId=&dialogID=14974886&stateId=1%200%2014978598
and looking a tthe code, I am getting an error on: "OpenReport" at the line below in Form_load
Set Report = Appl.OpenReport("K:\DCMS\R
I am not sure what is going on. Can you help me there.
p
What is the error?
What code are you using?
What references did you add to the project?
mlmcc
What code are you using?
What references did you add to the project?
mlmcc
ASKER
mlmcc:
this is all the code I adopted:
Option Explicit
Dim Appl As New Application
Dim Report As Report
Dim WithEvents CrSecRH As Section 'dim them with events so we can access the format event
Dim WithEvents CrSecPH As Section 'dim them with events so we can access the format event
Dim CrSecs As Sections
Public Pic1 As OLEObject 'Dim an object for the ole pictures so we can change the pic
Public Pic2 As OLEObject
Private Sub CrSecPH_Format(ByVal pFormattingInfo As Object)
Set Pic1.FormattedPicture = LoadPicture(gPicturePath & "111111.jpg") 'changes the pic in the Page Header
End Sub
Private Sub CrSecRH_Format(ByVal pFormattingInfo As Object)
Set Pic2.FormattedPicture = LoadPicture(App.Path & "\Tiles.bmp") 'changes the pic in the Report Header
End Sub
Private Sub Form_Load()
Set Report = Appl.OpenReport("K:\DCMS\R eports\" & "pic.rpt", 1) 'opens the rpt.
Set CrSecPH = Report.Sections("PH") ' set this section object to the page header
Set CrSecRH = Report.Sections("RH") ' set this section object to the report header
For I = 1 To CrSecPH.ReportObjects.Coun t 'Loop through the report objects and see if they are pictures
If CrSecPH.ReportObjects(I).K ind = crOleObject Then ' if it is a CrOleObject then
Set Pic1 = CrSecPH.ReportObjects(I) 'Set the pic1 object to the Ole Report object
End If
Next I
For I = 1 To CrSecRH.ReportObjects.Coun t 'loop through the report objects and see if they are pictures
If CrSecRH.ReportObjects(I).K ind = crOleObject Then ' if it is a CrOleObject then
Set Pic2 = CrSecRH.ReportObjects(I) 'Set the pic2 object to the Ole Report object
End If
Next I
crReportViewer.ReportSourc e = Report
crReportViewer.ViewReport 'Preview the report
crReportViewer.Zoom 100
End Sub
it crashes at: Appl.OpenReport
the references are
Crystal Reports 9 activex Designer run time
crystal report viewer 9
and rest of them are the same as in the example code.
this is all the code I adopted:
Option Explicit
Dim Appl As New Application
Dim Report As Report
Dim WithEvents CrSecRH As Section 'dim them with events so we can access the format event
Dim WithEvents CrSecPH As Section 'dim them with events so we can access the format event
Dim CrSecs As Sections
Public Pic1 As OLEObject 'Dim an object for the ole pictures so we can change the pic
Public Pic2 As OLEObject
Private Sub CrSecPH_Format(ByVal pFormattingInfo As Object)
Set Pic1.FormattedPicture = LoadPicture(gPicturePath & "111111.jpg") 'changes the pic in the Page Header
End Sub
Private Sub CrSecRH_Format(ByVal pFormattingInfo As Object)
Set Pic2.FormattedPicture = LoadPicture(App.Path & "\Tiles.bmp") 'changes the pic in the Report Header
End Sub
Private Sub Form_Load()
Set Report = Appl.OpenReport("K:\DCMS\R
Set CrSecPH = Report.Sections("PH") ' set this section object to the page header
Set CrSecRH = Report.Sections("RH") ' set this section object to the report header
For I = 1 To CrSecPH.ReportObjects.Coun
If CrSecPH.ReportObjects(I).K
Set Pic1 = CrSecPH.ReportObjects(I) 'Set the pic1 object to the Ole Report object
End If
Next I
For I = 1 To CrSecRH.ReportObjects.Coun
If CrSecRH.ReportObjects(I).K
Set Pic2 = CrSecRH.ReportObjects(I) 'Set the pic2 object to the Ole Report object
End If
Next I
crReportViewer.ReportSourc
crReportViewer.ViewReport 'Preview the report
crReportViewer.Zoom 100
End Sub
it crashes at: Appl.OpenReport
the references are
Crystal Reports 9 activex Designer run time
crystal report viewer 9
and rest of them are the same as in the example code.
Is this on the machine with Crystal?
Try changing these lines
Dim Appl As New Application
Dim Report As Report
to
Dim Appl As New CRAXDRT.Application
Dim Report As CRAXDRT.Report
mlmcc
Try changing these lines
Dim Appl As New Application
Dim Report As Report
to
Dim Appl As New CRAXDRT.Application
Dim Report As CRAXDRT.Report
mlmcc
ASKER
mlmcc:
I changed that now I am stuck in loop.
For I = 1 To CrSecD.ReportObjects.Count
If CrSecD.ReportObjects(I).Ki nd = crOLEObject Then
Set Pic1 = CrSecD.ReportObjects(I)
End If
Next I
"Set Pic1 = CrSecD.ReportObjects(I)" line never executes. as the KIND =101 and the left side is never 101
I am not sure what is going on? can you help me there please.
p
I changed that now I am stuck in loop.
For I = 1 To CrSecD.ReportObjects.Count
If CrSecD.ReportObjects(I).Ki
Set Pic1 = CrSecD.ReportObjects(I)
End If
Next I
"Set Pic1 = CrSecD.ReportObjects(I)" line never executes. as the KIND =101 and the left side is never 101
I am not sure what is going on? can you help me there please.
p
Where is the OLE Object?
How is CrSecD.ReportObjects declared?
mlmcc
How is CrSecD.ReportObjects declared?
mlmcc
ASKER
Dim WithEvents CrSecD As CRAXDRT.Section
I had CR 9 and 8.5 installed together. That was causing to bring diff DLL link. So, I reformated my compter and Now It works fine. The only thing is I just need to print it directly without showing to the user. Only that part is left.
paul
I had CR 9 and 8.5 installed together. That was causing to bring diff DLL link. So, I reformated my compter and Now It works fine. The only thing is I just need to print it directly without showing to the user. Only that part is left.
paul
Instead of these lines
crReportViewer.ReportSourc e = Report
crReportViewer.ViewReport 'Preview the report
crReportViewer.Zoom 100
Try
Report.PrintOut
mlmcc
crReportViewer.ReportSourc
crReportViewer.ViewReport 'Preview the report
crReportViewer.Zoom 100
Try
Report.PrintOut
mlmcc
ASKER
mlmcc:
in the Print_click() event I have:
Load fBadgePrint
in the form load i have:
Private Sub Form_Load()
Dim I As Integer
Set Report = Appl.OpenReport("C:\DCMS\R eports\Bad ge.rpt", 1)
Report.ParameterFields.Get ItemByName ("pPID").A ddCurrentV alue gCRParmPatientId
Report.ParameterFields.Get ItemByName ("pUID").A ddCurrentV alue gCRParmUnitCode
Set CrSecD = Report.Sections("D")
For I = 1 To CrSecD.ReportObjects.Count 'Loop through the report objects and see if they are pictures
If CrSecD.ReportObjects(I).Ki nd = crOleObject Then
Set Pic1 = CrSecD.ReportObjects(I)
ElseIf CrSecD.ReportObjects(I).Ki nd = crBoxObject Then
If CrSecD.ReportObjects(I).Na me = "Box1" Then
Set CrBox1 = CrSecD.ReportObjects(I)
CrBox1.FillColor = fBadge.lblFlag.BackColor
Else
Set CrBox2 = CrSecD.ReportObjects(I)
CrBox2.FillColor = fBadge.fraBadge.BackColor
End If
End If
Next
Report.PrintOut
Set Report = Nothing
Set CrSecD = Nothing
End Sub
It prints fine but a empty form stays in my vb project.
Also it is confirming the print diaolog box. however I did not ask in the question you do not have to answer it. just let us get it done with it. thanks againg
paul
in the Print_click() event I have:
Load fBadgePrint
in the form load i have:
Private Sub Form_Load()
Dim I As Integer
Set Report = Appl.OpenReport("C:\DCMS\R
Report.ParameterFields.Get
Report.ParameterFields.Get
Set CrSecD = Report.Sections("D")
For I = 1 To CrSecD.ReportObjects.Count
If CrSecD.ReportObjects(I).Ki
Set Pic1 = CrSecD.ReportObjects(I)
ElseIf CrSecD.ReportObjects(I).Ki
If CrSecD.ReportObjects(I).Na
Set CrBox1 = CrSecD.ReportObjects(I)
CrBox1.FillColor = fBadge.lblFlag.BackColor
Else
Set CrBox2 = CrSecD.ReportObjects(I)
CrBox2.FillColor = fBadge.fraBadge.BackColor
End If
End If
Next
Report.PrintOut
Set Report = Nothing
Set CrSecD = Nothing
End Sub
It prints fine but a empty form stays in my vb project.
Also it is confirming the print diaolog box. however I did not ask in the question you do not have to answer it. just let us get it done with it. thanks againg
paul
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mlmcc:
It worked find but now i need to accept the solution which is scattered. I think it would be nice that you put the code in one of your replied so that I can accept it because the code I put here would not let me accept it.
p
It worked find but now i need to accept the solution which is scattered. I think it would be nice that you put the code in one of your replied so that I can accept it because the code I put here would not let me accept it.
p
ASKER
mmlc just copy and paste this one and I will accept it. p
in the Print_click() even::
Load fBadgePrint
unload fBadgePrint
in the form:
Private Sub Form_Load()
Dim I As Integer
Set Report = Appl.OpenReport("C:\DCMS\R eports\Bad ge.rpt", 1)
Report.ParameterFields.Get ItemByName ("pPID").A ddCurrentV alue gCRParmPatientId
Report.ParameterFields.Get ItemByName ("pUID").A ddCurrentV alue gCRParmUnitCode
Set CrSecD = Report.Sections("D")
For I = 1 To CrSecD.ReportObjects.Count 'Loop through the report objects and see if they are pictures
If CrSecD.ReportObjects(I).Ki nd = crOleObject Then
Set Pic1 = CrSecD.ReportObjects(I)
ElseIf CrSecD.ReportObjects(I).Ki nd = crBoxObject Then
If CrSecD.ReportObjects(I).Na me = "Box1" Then
Set CrBox1 = CrSecD.ReportObjects(I)
CrBox1.FillColor = fBadge.lblFlag.BackColor
Else
Set CrBox2 = CrSecD.ReportObjects(I)
CrBox2.FillColor = fBadge.fraBadge.BackColor
End If
End If
Next
Report.PrintOut, False
Set Report = Nothing
Set CrSecD = Nothing
End Sub
in the Print_click() even::
Load fBadgePrint
unload fBadgePrint
in the form:
Private Sub Form_Load()
Dim I As Integer
Set Report = Appl.OpenReport("C:\DCMS\R
Report.ParameterFields.Get
Report.ParameterFields.Get
Set CrSecD = Report.Sections("D")
For I = 1 To CrSecD.ReportObjects.Count
If CrSecD.ReportObjects(I).Ki
Set Pic1 = CrSecD.ReportObjects(I)
ElseIf CrSecD.ReportObjects(I).Ki
If CrSecD.ReportObjects(I).Na
Set CrBox1 = CrSecD.ReportObjects(I)
CrBox1.FillColor = fBadge.lblFlag.BackColor
Else
Set CrBox2 = CrSecD.ReportObjects(I)
CrBox2.FillColor = fBadge.fraBadge.BackColor
End If
End If
Next
Report.PrintOut, False
Set Report = Nothing
Set CrSecD = Nothing
End Sub
Simply accept my last comment. Anybody who looks at this will read through the discussion and see the final code.
mlmcc
mlmcc
Glad i could help
mlmcc
mlmcc
“You can now place pictures and graphics in a report through a link stored in a
database, so that it is no longer necessary to store images within the
database. This new feature supports the common practice of storing images
on a web server and storing references to those images in a database”
Gary