Need to display an image on a report if a field has info

faesce

Registered User.
Local time
Today, 08:56
Joined
Feb 16, 2012
Messages
22
Hello. I'm trying to do what should be easy, I just don't know how to do it. I've got a report that works great, I just need to add in an image that displays under the condition that a field has info in it.

To be specific:

if FIELD1 = "PAID"
then my image IMAGE1 will display

if FIELD1 is blank
then nothing displays (or a blank.jpg or something)


Note: Sometimes FIELD1 is marked as "PAID", sometimes it is marked as "CC PAID", sometimes abbreviated as "CC PD", or another variation. Can my image displaying be conditional on the field containing ANY info, or does it have to be exact words every time?

I'm not sure how to go about doing this. Would really appreciate the help!

Thanks!
 
Is this a single image on the report, or an image for each record meeting the criteria?
 
An image for each record meeting the criteria. I essentially want to print a CREDIT CARD PAID type of image instead of having to go through and stamp a bunch every day.
 
Ok, the approach i would suggest is to place the image on the report but make it invizible (set Properties>>Visible = FALSE). Then in the OnFormat event for the section of the report you have placed the image in (probably Detail) place some code to identify if you want the image displayed. EG

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz(Field1,0) = 0 Then Exit Sub'field is null or "" so no image required
Me.ImageControl.Visible = True
End Sub

replace Field1 with the field that contains the data to query and ImageControl with the name of the image control.
 
I'm not sure what you mean by image control. I assumed that was the name of my image, but that doesn't work. In Report view, it doesn't show. In Print Preview view, it shows on every record.
 
The picture you are displaying is in a control. The most probable is an Image Control.

Have a look at the attached. It contains a simple table with a few null values and a report with an image that is only displayed for records that are not null
 

Attachments

This is what I'm using but it simply isn't working. In print preview mode, it is pulling the image on every record, regardless if Custom4 is null or not. In Report view, it doesn't show at all.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Nz([Custom4], 0) = 0 Then
Me.OLEUnbound284.Visible = False 'field is null or "" so no image required
Else
Me.OLEUnbound284.Visible = True
End If
End Sub

My Custom4 field is text, not a number value. Does this matter?
 
That is strange. I have used this method a number of times. Is it possible for you to attach your DB (sensitive data removed) or stick it on a hosting site and provide a link?
 
Not really. Its a pretty large database.
 
Could you copy the table and report to a blank database?
 
I think I managed to strip out enough. I'll send a PM with a link.
 
That is strange. In testing NZ([Custom4],0) = 0, so the code should work....but it does not!!!!:banghead::banghead::banghead:

Never mind, there is always more than 1 way to skin a cat they say, so....
Replace If Nz([Custom4], 0) = 0 Then with If [Custom4] & "" = "" Then
 
That works! Well, it doesn't work in report view but in print preview it does. Many many thanks!
 
Uh oh, I noticed a strange side effect... completely confused as to what is happening.

I have another field Custom10 that simply pulls and prints on the report. The info is in the table, and it shows up in report view, but when I print or look in print preview, this particular field sometimes doesn't show up. This field contains only a single letter, either a T or a C. Why the heck would this happen? Seems completely unrelated but the ONLY thing I've done was added in my image and your code.
 
Based on the version you set up for me, it could simply be the size of the control. Make it slightly longer (Set right alignment if you need the letter to stay that close to the label next to it), or reduce the font.
 
I swear access is so bizarre sometimes. I've changed nothing and now it suddenly works again. I had about 250 pages print out yesterday with about half of them missing Custom10. I really don't get it.

Anyhow, I seem to be all set, thank you very much!
 

Users who are viewing this thread

Back
Top Bottom