Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Images in Reports


Message #1 by John Walborn <JWalborn@m...> on Tue, 13 Feb 2001 14:13:55 -0700
> Is there a way to set images on reports at run-time? I am making a report
> for security purposes of "barred" members and would like to include a
> picture of those members. Does anyone know if/how I can use LoadPicture 
to
> place an image in an "Image" control on a report.
> 
> Thanks!


Here is code which does what you describe.  

1.  The database I used has one table, the fields are a primary key and 
Image.  Image contains the fully qualified path and file name.  It could 
also just be the image file name with the path to your image directory 
provided else where e.g. hardcoded in your code or a registry setting.

2.  For this sample, I created one form based on my image table (tblImages)
To this form I added a buttons which previews the report.  The report 
contains a label control and am image control. The label is named 
lblMemberID.  It has to be a label because VB will not allow you to 
use "SetFocus" with the TextBox control when the report is activating.

Here is the code:


Private Sub Report_Activate()
    Dim imgNew As Image  ' Your alias to the control on the report
    Dim t As Label       ' A label for text such as member name
    
    Set t = Me.lblMemberID  ' The label is an object so you must 'set' the 
                            ' reference to it. 
    t.Caption = Form_frmImages.txtMember  ' Change the text. 
    Set imgNew = Me.imgDynamic  ' Alias the image control
    imgNew.Picture = Form_frmImages.txtImagePath  

End Sub


I used the report's Activate event here, you could very well use the 
Report_Open event.   This sample uses MS Access 2000 and VBA.  It should 
work with Crystal Reports.

  Return to Index