Displaying an image on report if certain condition is met? (1 Viewer)

YNWA

Registered User.
Local time
Today, 00:59
Joined
Jun 2, 2009
Messages
905
Hi,

i have sorted an issue I have to only display an image when a field (paiddate) is not null.

I use this code:

Code:
Private Sub Report_Load()
On Error GoTo ErrHandler
  
    If IsDate(paiddate) Then
        Paid.Visible = True
    Else
        Paid.Visible = False
    End If
  
exitErr:
    Exit Sub
ErrHandler:
    MsgBox "Error detected, error # " & Err.Number & ", " & Err.Description, vbOKOnly, "Error"
    Resume exitErr

End Sub

And it works fine.

However, if I copy the report and add a parameter to the query (eg. to show all invoices between 2 sets of dates), the code doesn't seem to work and image is visible on every invoice.

The first invoice where it works is always 1 invoice however the 2nd way I am trying to do involves bring back a number of invoices (Reports fed by Queries).

Any ideas?
 

boblarson

Smeghead
Local time
Yesterday, 16:59
Joined
Jan 12, 2001
Messages
32,059
Don't use the Load event. Use the ON FORMAT event of the section where the controls reside. And, if you have Report View in use as well you need to also have it in the On PAINT event. If you do need it in both, just create a new procedure in the report's module and then call it from each of the events I noted.
 

YNWA

Registered User.
Local time
Today, 00:59
Joined
Jun 2, 2009
Messages
905
Don't use the Load event. Use the ON FORMAT event of the section where the controls reside. And, if you have Report View in use as well you need to also have it in the On PAINT event. If you do need it in both, just create a new procedure in the report's module and then call it from each of the events I noted.

Do I just copy that code into the OnFormat?

I never wrote that code so not sure what I need if I need to rewrite it.
 

boblarson

Smeghead
Local time
Yesterday, 16:59
Joined
Jan 12, 2001
Messages
32,059
Yep, you would move it to that event. And I would just change one thing - use the ME keyword so that there is no ambiguity as to what is being referred to:
Code:
If IsDate([B]Me.[/B]paiddate) Then
[B]   Me.[/B]Paid.Visible = True
Else
[B]   Me.[/B]Paid.Visible = False
End If
 

Users who are viewing this thread

Top Bottom