Link to home
Start Free TrialLog in
Avatar of dhamijap
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.ParameterFieldDefinitions
Dim CrParamDef As CRAXDRT.ParameterFieldDefinition '

Private Sub Form_Load()
    Set CrApp = New CRAXDRT.Application
    Set CrReport = CrApp.OpenReport("MyReportName.rpt")
   
    crReportViewer.Top = 0
    crReportViewer.Left = 0
    crReportViewer.Width = Me.ScaleWidth
    crReportViewer.Height = Me.ScaleHeight
    CrReport.ParameterFields.GetItemByName("pPID").AddCurrentValue 11111
    CrReport.ParameterFields.GetItemByName("pUID").AddCurrentValue 'A'
    crReportViewer.ReportSource = CrReport    
    CrReport.ReadRecords
    crReportViewer.ViewReport
    .
    .
    .
Thanks
Avatar of crgary_tx
crgary_tx
Flag of United States of America image

I guess to adding the picture dynamically with a path stored as d/b field is a new feature in CR XI. Here is the quote from BO:

“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
 

Avatar of dhamijap
dhamijap

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
Avatar of Mike McCracken
Try

CrReport.PrintReport False

mlmcc
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
You can try.  CR8 and 8.5 had limited picture capability.

mlmcc
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\Reports\" & "pic.rpt", 1)

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
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\Reports\" & "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.Count 'Loop through the report objects and see if they are pictures
      If CrSecPH.ReportObjects(I).Kind = 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.Count 'loop through the report objects and see if they are pictures
      If CrSecRH.ReportObjects(I).Kind = 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.ReportSource = 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.

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
mlmcc:
I changed that now I am stuck in loop.
For I = 1 To CrSecD.ReportObjects.Count
        If CrSecD.ReportObjects(I).Kind = 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
Where is the OLE Object?

How is CrSecD.ReportObjects declared?

mlmcc
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
Instead of these lines

    crReportViewer.ReportSource = Report
    crReportViewer.ViewReport 'Preview the report
    crReportViewer.Zoom 100


Try

Report.PrintOut

mlmcc
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\Reports\Badge.rpt", 1)
    Report.ParameterFields.GetItemByName("pPID").AddCurrentValue gCRParmPatientId
    Report.ParameterFields.GetItemByName("pUID").AddCurrentValue 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).Kind = crOleObject Then
            Set Pic1 = CrSecD.ReportObjects(I)
        ElseIf CrSecD.ReportObjects(I).Kind = crBoxObject Then
            If CrSecD.ReportObjects(I).Name = "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
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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\Reports\Badge.rpt", 1)
    Report.ParameterFields.GetItemByName("pPID").AddCurrentValue gCRParmPatientId
    Report.ParameterFields.GetItemByName("pUID").AddCurrentValue 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).Kind = crOleObject Then
            Set Pic1 = CrSecD.ReportObjects(I)
        ElseIf CrSecD.ReportObjects(I).Kind = crBoxObject Then
            If CrSecD.ReportObjects(I).Name = "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
Simply accept my last comment.  Anybody who looks at this will read through the discussion and see the final code.

mlmcc
Glad i could help

mlmcc