Having trouble with image visibility/not on a report (1 Viewer)

mlanciano7

New member
Local time
Yesterday, 23:41
Joined
Nov 6, 2023
Messages
6
I am working on an access database for digitizing SDS sheets, and I want images to show or not show depending on the content of the record. I used the following section of code repeatedly for each image set where the red image shows if the corresponding text says anything other than no and the grey image shows when the text says no. Each text box has a name and each image has a name.


If Me.TXT_Health = "No" Then
Me.IMG_HEALTH_RED.Visible = False
Me.IMG_HEALTH_BW.Visible = True

Else

Me.IMG_HEALTH_RED.Visible = True
Me.IMG_HEALTH_BW.Visible = False

End If


My issue lies when I run the report, only one of the entries follows the visible or not rules correctly. Below are the three entries on the report and as you can see only one that is correct is the last entry. Is there a way that I can use the visible or not VBA code to have these images match the text boxes per record correctly? If you need any other information let me know.

TIA!!!

1699307446713.png

1699307468194.png

1699307492902.png
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:41
Joined
Oct 29, 2018
Messages
21,581
Hi. Welcome to AWF!

Are those Yes/No fields? If so, you don't need to use double quotes around them. Try simply:

If Me.TXT_Health = No Then

Or even:

If Me.TXT_Health = False Then
 

mlanciano7

New member
Local time
Yesterday, 23:41
Joined
Nov 6, 2023
Messages
6
Hi! Thanks for welcoming me! I've been getting deeper into the access VBA and I've finally stumped myself lol

They are not yes no fields. There is data in the text fields or no if that field doesn't apply (For example on entry one there is all the text in the warning box)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:41
Joined
Oct 29, 2018
Messages
21,581
Hi! Thanks for welcoming me! I've been getting deeper into the access VBA and I've finally stumped myself lol

They are not yes no fields. There is data in the text fields or no if that field doesn't apply (For example on entry one there is all the text in the warning box)
When you say FieldName="No" then you're expecting that field to contain the word "No" in it. Is that what you have?
 

mlanciano7

New member
Local time
Yesterday, 23:41
Joined
Nov 6, 2023
Messages
6
Yes that is what the field contains. You can see examples of what the fields contain in the images I attached for reference :)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 20:41
Joined
Oct 29, 2018
Messages
21,581
Yes that is what the field contains. You can see examples of what the fields contain in the images I attached for reference :)
Which one of those is TXT_Health?
 

mlanciano7

New member
Local time
Yesterday, 23:41
Joined
Nov 6, 2023
Messages
6
TXT_Health is the health hazard text field and is associated with the left most images. I understand that the health hazard field is no in all records therefore all grey.

Just to clarify its all of the image sets that I am having an issue with not just the one. I copied the code for each set of images and text.

Exclamation images with warning text
Flame images with flammable
Etc.

The visibility code I wrote does not correctly show the images for each individual record but picks one record and sets that visibility for all records. I am trying to make the visibility be correct for each individual record.
 

KitaYama

Well-known member
Local time
Today, 12:41
Joined
Jan 6, 2022
Messages
1,594
The visibility code I wrote does not correctly show the images for each individual record but picks one record and sets that visibility for all records. I am trying to make the visibility be correct for each individual record.
Where have you used that code?
It should be onFormat event of the section.
If your textboxes and the images are in Details section, then your IF statement should be used in Detail's OnFormat event.

Can you upload a sample file?
 

mlanciano7

New member
Local time
Yesterday, 23:41
Joined
Nov 6, 2023
Messages
6
I have the code in the OnLoad event for the entire report. I tried to put it into the OnFormat event for the detail section and it shows them all as visible when very clearly some should be not be visible. Any other ideas?

1699362679166.png
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:41
Joined
May 21, 2018
Messages
8,643
I have the code in the OnLoad event for the entire report. I tried to put it into the OnFormat event for the detail section and it shows them all as visible when very clearly some should be not be visible. Any other ideas?
It cannot be onload since that only occurs once and not for each record. The OnFormat of the detail section is correct, but all of this will only work in print preview. If you simply click on the report it will come up in report view and show all.
 

mlanciano7

New member
Local time
Yesterday, 23:41
Joined
Nov 6, 2023
Messages
6
Okay that works for the print preview just like you said. Is there a way to get that to work in report view?
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:41
Joined
May 21, 2018
Messages
8,643
Is there a way to get that to work in report view?
Not as far as I know. I doubt it.
 

Users who are viewing this thread

Top Bottom