Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unable to add Picture Object to Existing report 1

Status
Not open for further replies.

panksy

Programmer
Oct 27, 2003
11
IN
Hi all,
I am trying to add a PictureObject to an existing report's Report Header Section through VBScript code in my ASP page. I am able to get reference to the RH section and get its various properties but unable to add a new object to the report. Here is a bit of code I tried for adding a simple TextObject.

Code:
Set rhSection = session("oRpt").Sections.Item(1)
Response.write(rhSection.ReportObjects.Count)
Set rhTextObject = rhSection.AddTextObject ("My Custom Header",1440, 1440)
Response.write(rhSection.ReportObjects.Count)

Both the "Reponse.write" give the same count. Can anybody point out the mistake. Using Crystal Reports 9.

Thanks in advance.

panksy
 
Creating a new object in a report (as opposed to modifying an existing object) requires the use of CRAXDDRT.DLL, not CRAXDRT.DLL. However, once you start creating new objects in reports, you run into a royalty licensing issue. Crystal requires you to pay a royalty for the use of CRAXDDRT.DLL. I don't really know the particulars; you can visit the Crystal Decisions website to find out more (In CR 8.5 they had info in the help file, but it's been replaced by a link to the Crystal Decisions site in the CR 9 help files).

The simplest workaround is to already have an object on your report and simply change the characteristics of that object rather than try to create a new one. The "Add" methods of the section object exist to allow a developer to integrate Crystal into an application which would allow end users to create Crystal reports from scratch. Obviously, that would allow a developer to create, essentially, a competing product to CR, so Crystal Decisions obviously wants a piece of the pie (hence, the royalty).
 
I have now added a picture object to my report and I want to change its location dynamically on loading of my ASP page. After this I am exporting this report to .pdf. I can use the SetOleLocation to set its location dynamically by formating the section but the support on crystal decisions says :
"Formatting performed in the Section Format event is only shown in the report Preview Window. If the report is printed or exported, the code in the Section Format event will not be executed."

Is there some other way of doing this ?

FVTrainer you are right about this license thing crystal decisions gives a patch for adding objects to a report on the fly but not for free :-(
 
Well, I think you're looking at doing the change in the wrong place. The Section Format fires during the printing of the report. But completely prior to that, you can set the position of the picture object in the following manner:

Dim crSection
Dim crOLEOBJECT
Dim crObject

Set crSection = crRpt.Sections("RH")

For x = 1 To crSection.ReportObjects.Count
If crSection.ReportObjects.Item(x).Kind = 6 Then 'crOleObject
Set crOLEOBJECT = crSection.ReportObjects.Item(x)
Exit For
End If
Next 'x

With crOLEOBJECT
.Left = 4220
End With

'Now print or export the report
'exporting is shown below

Set crExport = crRpt.ExportOptions

crExport.DestinationType = crEDTDiskFile
crExport.DiskFileName = App.Path & "\sample1.pdf"
crExport.FormatType = crEFTPortableDocFormat

crRpt.Export False

I've included some code related to exporting, but that is not particularly relavent if you're exporting from within the viewer control.

Hopefully, the above code will help meet your needs.
 
I can change the Left, Height etc. But I want to change the source of the Picture Object i.e. I want to change the image itself. For e.g. I want to change the image displayed from img1.jpeg to img2.jpeg. Sorry for using the word "location". I used it because I thought this can be done using the method setOleLocation. Now I am not sure whether this can be done using it.
 
oh...well...hmmm...I've done this in the context vb but not asp (and not exporting).

Do you have a limited number of jpegs to show or are there more than conditional suppression would reasonably address? Another approach would be to put your jpeg's into a database table and then determine logic that would allow you to join to the table and show the correct picture...
 
The image I want to include has the same name and location in the directory structure but it is updated each day and I want to show the new image whenever I see it on my ASP.
And the problem is that it shows the image which i added into the crystal report at the time of creation of the report. So thats why i was trying to change the source of my picture object.
Now it might be that whenever the report is exported through ASP the image file is not loaded again but it uses the image which is present in the .rpt file.

The database option is next in line if I can't do this way.
 
I got this thing working(at least for a while) by using an ole object pointing to a file. This file is the image file which i want to load in the report and any change is reflected in the exported report too. But now another problem has crept in, I am using IIS and viewing the report by typing a http ://localhost.....URL. Now any change in the image is reflected fine but when i go to another machine and view it by giving the IP of my machine the changes in the image file are not reflected. Probably this is not a Crystal report issue but some permissions settings in IIS or someplace. Shared this thing as it might work for someone else with right IIS settings.

Anyway I have given up after this arbitrary problem and now trying to work out the DB option. Any pointers to samples of handling of Image datatype in MSSQL ?

FVTrainer, Thanks a lot for all the help
rgds,
panksy
 
You may have already figured this out, but here is some sample vb code that allows you to load an image into a BLOB data type field in a sql server table:

Private Sub ImportBLOB(cn As ADODB.Connection)

Dim rs As New ADODB.Recordset
Dim stm As ADODB.Stream

Set stm = New ADODB.Stream

'Skip any table-not-found errors.
On Error Resume Next
cn.Execute "drop table BinaryObject"

On Error GoTo 0
'Create the BinaryObject table.
cn.Execute "create table BinaryObject " & _
"(blob_id int IDENTITY(1,1), " & _
"blob_filename varchar(256), " & _
"blob_object image)"

rs.Open "Select * from BinaryObject Where 1=2", cn, adOpenKeyset, adLockOptimistic
'Read the binary files from disk.
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile App.Path & "\BLOBsample.jpg"

rs.AddNew
rs!blob_filename = App.Path & "\BLOBsample.jpg"
rs!blob_object = stm.Read

'Insert the binary object into the table.
rs.Update

rs.Close
stm.Close

Set rs = Nothing
Set stm = Nothing

lblResults.Visible = True

End Sub

Once you have it in the database, it should behave just like any other field, as far as Crystal is concerned.
 
Yeah I am done with this.
Thanks anyways.

Panksy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top