Results 1 to 9 of 9

Thread: Crystal Reports Image at Runtime [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    34

    Thumbs up Crystal Reports Image at Runtime [RESOLVED]

    Hi,

    I am using VB6, Crystal Reports 8.5, .rpt report files and the CRViewer to show the reports. Data source is either Access or SQL.

    I need to be able to set an image in the report at runtime to the logo of the company selected. I am happy to use either an image in a directory (path provided) or an image stored in a database (passed by ADO Recordset).

    Can anyone tell me how this can be done, or just start me off on the right track as I am stumped!!

    Thanks in advance.

    TC

    I had posted this in the Crystal Reports section but to no avail!!
    Last edited by TC99; Apr 6th, 2003 at 01:04 PM.

  2. #2

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    34
    Does anybody know how to do this???

  3. #3
    Addicted Member
    Join Date
    Apr 1999
    Posts
    178
    Code:
    Private Sub Section2_Format(ByVal pFormattingInfo As Object)
    
      Set Picture1.FormattedPicture = LoadPicture("c:\aImages\inside.jpg") 
    
    end sub
    See page 19 in this pdf file for a more detail example http://support.crystaldecisions.com/...8-ocxtordc.pdf

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2002
    Location
    England
    Posts
    34
    Hi Ken,

    Thanks for the pdf link. It is just what I needed and works really well.

    TC

  5. #5
    Addicted Member
    Join Date
    Jan 2002
    Location
    http://www.vbforums.com
    Posts
    164

    Unhappy I can't make it work.


    I tried your way of changing the image but I get a

    "Permission denied."

    error message.

    VB Code:
    1. Set crxPicObj = Report.Sections(2).ReportObjects.Item(18)
    2.     With rsTemp
    3.         If .State = adStateOpen Then
    4.             .Close
    5.         End If
    6.         .Source = "SELECT * FROM CSREPSETUP"
    7.         .Open
    8.        
    9.         If .RecordCount <> 0 Then
    10.              sTemp = App.Path & "\Images\TempPic.jpg"
    11.              If Len(Dir(sTemp)) > 0 Then
    12.                  Kill sTemp
    13.              End If
    14.             lngSize = 0
    15.             lngOffSet = 0
    16.             f = FreeFile
    17.            
    18.             Open sTemp For Binary As #f
    19.             lngSize = rsTemp("Image").ActualSize
    20.            
    21.             Do While lngOffSet < lngSize
    22.                 bytChunk() = rsTemp("Image").GetChunk(CHUNKSIZE)
    23.                 Put #f, , bytChunk()
    24.                 lngOffSet = lngOffSet + CHUNKSIZE
    25.             Loop
    26.             Close #f
    27.            
    28.             Set crxPicObj.FormattedPicture = LoadPicture(sTemp) 'This is where the error occurs.
    29.             Kill sTemp
    30.         End If
    31.     End With
    Last edited by jeremy_ckw; Apr 8th, 2003 at 12:23 AM.
    "If ignorance is bliss, that probably explain why I'm in a such a mess right now!!"

  6. #6
    Addicted Member
    Join Date
    Apr 1999
    Posts
    178
    The image path can only be set in the section format sub.

    I assume from your code that the image is in section2 on the report.

    Code:
    'Double-click anywhere in section 2 to get to the format sub.
    Private Sub Section2_Format(ByVal pFormattingInfo As Object)
    
      Set crxPicObj.FormattedPicture = LoadPicture(App.Path & "\Images\TempPic.jpg"
    ) 
    
    end sub
    Delete from your code

    Code:
    Set crxPicObj.FormattedPicture = LoadPicture(sTemp)
    Add the following code to

  7. #7
    Addicted Member
    Join Date
    Jan 2002
    Location
    http://www.vbforums.com
    Posts
    164
    Thanks for you reply!

    You are right, the image can only be set in the section event. I think I'm using a wrong way to do this.

    How do you double click on the section? I just have a crviewer on a form, that's all. Clicking it is like clicking any other components. It doesn't show me the section.

    Regards,
    "If ignorance is bliss, that probably explain why I'm in a such a mess right now!!"

  8. #8
    Addicted Member
    Join Date
    Apr 1999
    Posts
    178
    The report viewer is used to display a report. You still need to add a report to your application.

    From the main menu, select Project, Add Crystal Reports 8.5

    If you have an existing report, you can import it from here.

    This will create a report that will appear in the Designer section in the Project Window. Double click on that and a list of all designer objects will appear (ie your report). Double click on your report and it will open up like any other VB form. This is where you will double click on the picture to get to the format section.

    Read the link I gave above, it will show you how to interact between the viewer and you report.

    Hope this helps.

  9. #9
    Junior Member
    Join Date
    Apr 2003
    Location
    canada
    Posts
    16
    Originally posted by Ken Bradford
    The report viewer is used to display a report. You still need to add a report to your application.

    From the main menu, select Project, Add Crystal Reports 8.5

    If you have an existing report, you can import it from here.

    This will create a report that will appear in the Designer section in the Project Window. Double click on that and a list of all designer objects will appear (ie your report). Double click on your report and it will open up like any other VB form. This is where you will double click on the picture to get to the format section.

    Read the link I gave above, it will show you how to interact between the viewer and you report.

    Hope this helps.

    Could you please tell me how to add Crystal report to project?
    I went to the main menu and click "project", but there is no selection for adding Crystal report, only "data report", are you talking about that one?

    please help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width