Conditional visible states of fields (1 Viewer)

Gaztech

Member
Local time
Today, 19:01
Joined
Jan 5, 2021
Messages
39
Hi,
I have a small conundrum relating to the visible display of a field on one of my forms. This form is used for editing previously saved records.

I have a check box, which when checked I want a field to then become visible so that I can enter data into it. My two fields are called:
SUB_ASSY (the checkbox) and SUB_ASSY_REF (the field I need to control).

For entry I used this code:
Private SUB_ASSY_AfterUpdate()
If Me.SUB_ASSY = True Then
Me.SUB_ASSY_REF.Visible = True
Else
ME.SUB_ASSY_REF.Visible = False
End If
End Sub

This works but I don't just want to do this for entry purposes. If I then use the NEXT button and go to the next record, records that do not have the SUB_ASSY checkbox checked are shown on the screen but still show the SUB_ASSY_REF field as visible. When you go NEXT is the AfterUpdate code for the field ignored? I would have thought that since the record is fetched, the checkbox is updated with the new data for the next record so that code would work.

I'm assuming that since you physically did not click the checkbox, it doesn't work. In fact on any of these newly found records if I check and then un-check the box, the field does disappear as I would expect.

So, the code is ok - but only on "activating" the check box manually.

How can I show the NEXT database record with the field suppressed if the checkbox entry is FALSE and have it visible if the checkbox entry is TRUE for each newly found record? This must be something simple but it would seem that I can't see the wood for the trees on this one!

I tried adding a "BeforeUpdate" version of the code above (that seemed to make sense logically as surely this should run before you actually check the box) but that doesn't work. I guess I need to run this code when the record is found and displayed. I feel that I'm being a complete dummy here...

And oh yes... I'm new at this... :(

Comments please?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:01
Joined
May 7, 2009
Messages
14,626
add code to the Form's current event:

private sub form_current()
call SUB_ASSY_AfterUpdate
end sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:01
Joined
Feb 28, 2001
Messages
21,193
Arnel's answer should work unless there is something else in that routine besides what you showed us. Keep it simple? It will work fine!
 

Gaztech

Member
Local time
Today, 19:01
Joined
Jan 5, 2021
Messages
39
Wow! That was easy!

I didn't realise you could do that. That's a neat trick.

Many thanks guys as always. :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:01
Joined
Sep 21, 2011
Messages
9,314
If you think about it, you could probably just use ?
Code:
Me.SUB_ASSY_REF.Visible = Me.SUB_ASSY
 

Users who are viewing this thread

Top Bottom