Display Image Conditionally (2 Viewers)

DimWit

New member
Local time
Yesterday, 22:41
Joined
Dec 4, 2025
Messages
7
Overview: Students progress through a course of study broken into levels. When a level is complete, the user record is updated, indicating level completion via a Y/N field.

On a report I want to graphically indicate level completion with an .jpg icon in an image control. (This is located in a Group Header if that's relevant.)

When things didn’t go to plan and to assist in troubleshooting, I placed a checkbox control for the field next to the image control to be sure the data is being reported. (It is.)

I’ve tried using both the underlying field and the checkbox in a conditional to make the icon visible with no joy.
Field name = Lvl1
Checkbox = Lvl1Chk
Image = Lvl1Img

Syntax I’ve tried
Lvl1Img = Lvl1Ck (or using the underlying field [Lvl1])
Lvl1Img.Visible = Lvl1Ck ( “ )
Me!Lvl1Img.Visible = Me!Lvl1Ck ( “ )

I’ve placed code in
Report_Current()
GroupHeader1_Current() (GroupHeader1 is where the image control & CkBx reside)
GroupHeader1_Format()

And, based on some recommendations found elsewhere, I also placed code in
Lvl1Ck_AfterUpdate()
Me!Lvl1Img.Visible = Me!Lvl1Ck

None of this has worked. TIA for your assistance
DimWit as Flummoxed
 
What is (") all about?
I cannot see after update of a report control working? Not even sure why it would exist.
Not at my computer atm, on phone, so unsure which event, like Paint could be used.
 
Report sections have an On Format event that should be used to set controls visibility within that section. I would try something like:
Code:
Me.[Lvl1Img].Visible = Me.Lvl1

Using numbers in field names raise a red flag regarding normalization. Do you have Lvl2,…
 
DHookom beat me to it.

With Access, as you might remember from 20 years ago, it not only matters what you do but when you do it. The proper place to do anything in a report is usually a section-based event, like the Section_Format event.
 
What is (") all about?
I cannot see after update of a report control working? Not even sure why it would exist.
Not at my computer atm, on phone, so unsure which event, like Paint could be used.
Thanks Gasman. That was a ditto for the previous line. The formatting was changed making it confusing. Sorry.
 
You should be using . Rather than ! And perhaps use the picture property rather than controlsource

Me.Lvl1Img.picture = Me.Lvl1Ck.picture
 
You should be using . Rather than ! And perhaps use the picture property rather than controlsource

Me.Lvl1Img.picture = Me.Lvl1Ck.picture
CJ, can you explain your code? Maybe you know something that I don’t which is quite possible.
 
DHookom and ..Doc_Man
Thanks both for your very prompt response. Do not interpret my delay as disrespecting your diligence.
>>With Access, as you might remember from 20 years ago,...
Sorry Doc, I'm faking it until I make it here. I spent days looking at other forums and viewed some YT vids, and I can talk the coding syntax but am otherwise trying to piece things together. I appreciate both your assistance to this point. (Point taken when vs where.)
OK, here's the entirety of my code module

Option Compare Database

Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)

Me.Lvl1Img.Visible = Me.Lvl1
Me.Lvl2Img.Visible = Me.Lvl2
Me.Lvl3Img.Visible = Me.Lvl3

End Sub

After changes, I save, close, and restart Access before tying the updated code [based on watching 599cd vids]

The above code throws RTE 2465, Ms Access can't find the field "Lvl1" referenced to in your expression

Changing the expression to =me.Lvl1Ck throws RTE 94 Invalid use of Null

DHookom: Yes, there are three "Level" fields

Finally, without trying to wade through 1,000 pages of The Access Bible, can you recommend ways to get up to speed quickly, on form properties and other critical bits of knowledge?

DimWit as Grateful
 
Look on YouTube. Lots of videos for access on there.
You said your boolean control was lvl1chk?
 
Gasman
Yes, each of the Lvln fields is a Y/N and the checkbox control's data source corresponds to the field.
 
I could see the 'invalid use of null' being the result if some users not having completed any levels so the value in the Lvl field would be null.
 
Sorry, not absolutely sure what you're asking.
Lvl1Chk is a checkbox control with it's control source set to the db field Lvl1.
Is this what you're confirming?
 
CJ, can you explain your code? Maybe you know something that I don’t which is quite possible.
I misread the OP’s post, thought they were trying to populate an image control based on this line in the original post

Lvl1Img = Lvl1Ck
 
The above code throws RTE 2465, Ms Access can't find the field "Lvl1" referenced to in your expression
This is probably why the suggestion was made to use Dot notation and not Bang (!). With Dot you should get intellisense so when you type
Me.l then it will show all the objects starting with "l". Bang does not provide intellisense.
Changing the expression to =me.Lvl1Ck throws RTE 94 Invalid use of Null
In the format event it will run through every record. If you have a Null value then it will fail. However if me.lvl1Ck is a boolean field I think it is not possible for it to be null (or at least not easy). But you could try to protect that by
= nz(me.lvl1CK,0)
 
I think it is not possible for it to be null
confirmed - potentially it could be null for a new record, but when saved it will save as 0. If the field default value is set to 0 then it can never be null (unless your are in the table and swipe left) but it will still save as 0. The only time a checkbox on a form can be null is if it is unbound and you have not set its value to true or false. The user cane set it to null if the triple state property is set to yes
 
Can you assure us the record has been saved? Also, are the Lvl1,… fields are bound to controls in the section with the image controls?
 
use your Control not the fields in your table:
Code:
Private Sub GroupHeader1_Format(Cancel As Integer, FormatCount As Integer)

Me.Lvl1Img.Visible = Me.Lvl1Chk
Me.Lvl2Img.Visible = Me.Lvl2Chk
Me.Lvl3Img.Visible = Me.Lvl3Chk

End Sub
 

Users who are viewing this thread

Back
Top Bottom