Support in making my visible fields visible

Charlie100

New member
Local time
Today, 07:45
Joined
Nov 2, 2021
Messages
12
My access form has a series of fields which only appear on a certain criteria being input, normally yes or no. The code has been keyed in the build event menu and working perfectly for a new form.

When I try and open an existing form with the data contained, the fields which I expected to be visible are hidden, although once you say select yes in the field, the additional fields automatically appear with all the previous data displayed. Any ideas?

These are combi boxes with my inputs as

Private Sub fieldname1_AfterUpdate ()
If fieldname1.value="No" Then
Fieldname2.visible=false
Else
Fieldname2.visible=True
End if
End sub
 
add code also to the Form's Current Event:

private sub Form_Current()
Call fieldname1_AfterUpdate
end sub
 
Although calling the _AfterUpdate event is not wrong, I would not do it. I would create a new sub that handles just the hide/unhide functionality and call it from both of the events. This is a little cleaner because it isolates the code so that it will not be impacted if you add other code to the event procedures.

Programmers have an expectation regarding event procedure code and that expectation is that the ONLY time that code will be executed is when the event happens and calling the code from a different event breaks that contract. Probably nothing will ever go wrong but using defensive programming techniques is always good practice especially when it takes less than a minute to accomplish:)
 
Hi Pat, really appreciate your reply. Are you able to share the code which you're suggesting that I should use?
 
The code provided works perfectly on a single group of linked fields, however I have approximately five separate fields which have the visible (true/false) field codes. An error is displayed on form load if you try to apply to more than one as separate codes.
 
I managed to sort it.

private sub Form_Current()
Call fieldname1_AfterUpdate
Call fieldname2_AfterUpdate
Call fieldname3_AfterUpdate

Worked perfectly.👍🤞
 
who else.. take it!
 

Users who are viewing this thread

Back
Top Bottom