Clear "previous" picture from report? (1 Viewer)

Big Pat

Registered User.
Local time
Today, 23:43
Joined
Sep 29, 2004
Messages
555
Hi,

Records in my database contain the file paths of two pictures, a before and after, stored as txtPhotoPath and txtAFTERPhoto. On my report, I have two corresponding pictures, called RiskPhoto and AFTERPhoto.

I used the code below, which I adapted from something I found on this site, to display the pictures when the report is run. It's working fine - IN MOST CASES


Code:
Private Sub Report_Activate()
' "Requery" the pictures



On Error GoTo Err_cmdClose_Click

    'set picture paths
    Me.RiskPhoto.Picture = Me.txtPhotoPath
    Me.AFTERPhoto.Picture = Me.txtAFTERPhoto
    
Exit_cmdClose_Click:
    Exit Sub

Err_cmdClose_Click:
    If Err.Number = 2220 Then 'can't find the file
        Resume Next
    ElseIf Err.Number = 94 Then 'invalid use of null
        Me.RiskPhoto.Picture = ""
        Me.AFTERPhoto.Picture = ""
        Resume Next
    Else
        MsgBox Err.Description
        Resume Exit_cmdClose_Click
    End If

End Sub

However, we also have certain records WITHOUT an "after" picture, so txtAFTERPhoto is null in these cases. The problem is that rather than just printing an 'empty' picture, we're finding that the picture from the previous record is displayed in the report.

I think it's the error-handling that's at fault, but I'll be honest I don't really understand that bit.

I guess the previous picture is not being "cleared" but how do I achieve that?


Secondary question: To get this to work in the first place required a lot of trial and error. Mainly error in fact!! I now have this identical code in each of the following events:
  • GroupHeader0_Print(Cancel As Integer, PrintCount As Integer)
  • Report_Activate()
  • Report_Current()
  • Report_Page()

I don't know which one (or more?) is being fired when I run the report, and I don't know which if any them is redundant and should be deleted. I can live with them, though, if the first question above can be answered.

Thank you very much.
 

DCrake

Remembered
Local time
Today, 23:43
Joined
Jun 8, 2005
Messages
8,632
What I would do, which would be more informative to the user is to have a default "No Image available" picture. Then in your code adapt it as follows:

Code:
If Not IsNull(Me.txtPhotoPath) Then
    Me.RiskPhoto.Picture = Me.txtPhotoPath
Else
    Me.RiskPhoto.Picture = CurrentProject.Path & "\Images\NoImage.jpg"
End If

If Not IsNull(Me.txtAFTERPhoto) Then
    Me.txtAFTERPhoto.Picture = Me.txtAFTERPhoto
Else
    Me.txtAFTERPhoto.Picture = CurrentProject.Path & "\Images\NoImage.jpg"
End If

That way you will always display a picture and the user will know that there is no picture available, and not just not printed.

The CurrentProject.Path & "\Images\NoImage.jpg" is just for brevity. this is just an example to where the image is stored on the server/machine.

David
 

Big Pat

Registered User.
Local time
Today, 23:43
Joined
Sep 29, 2004
Messages
555
Thanks and sorry for taking so long to come back. As a stop-gap I had already told our users to use a blank picture (i.e. a jpeg of a white borderless rectangle) which they each had to copy to their PCs. We have four staff all with standalone PCs, not networked, so essentially we have four copies of the database, identical when we start, but then each with different client's data on them.

It's not fail-safe though, i.e. they might forget to select the blank picture occasionally. Is there a way to embed the blank picture in the database, so that it is selected by default if no other picture is chosen? I have thought about having the default value of the txtAFTERPhoto field set to the path of the blank jpeg, but that path is different on each PC. Additionally, I may consider installing this package for our clients too, so I'd rather not have to specify a path on their machines, that I would have no control over.
 

Simon_MT

Registered User.
Local time
Today, 23:43
Joined
Feb 26, 2007
Messages
2,177
There is a better way, answered on another posting.

Simon
 

Users who are viewing this thread

Top Bottom