Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking visibility property of controls to check box control 2

Status
Not open for further replies.

bphillips

Technical User
Feb 18, 2003
13
0
0
US
Is it possible to hide/reveal controls on a form depending on the value of a yes/no field on the form? For example, given a form named "MainForm", two controls named "OnlyIfIsTrue1" and "OnlyIfIsTrue2", respectively, and a check box named "IsTrue" bound to a yes/no field by the same name, is there an event procedure that you could link to IsTrue that would cause the other two controls to appear on the form if IsTrue was checked? Furthermore, if such a procedure exists, would it be possible to extend it to include subforms?
 
Sure is!

In the after_update event for the checkbox, you just need to add some vb code, i.e.:

If IsTrue = True Then
OnlyIfIsTrue.visibility = True
OnlyIfIsTrue.visibility = True
Else
OnlyIfIsTrue.visibility = False
OnlyIfIsTrue.visibility = False
End If


And to extend that to subforms, just add the subform name in there and there too is a visibility property for that just like the other controls.
 
Hi dakota81, you made a little error in your posting. Also it might be an idea to put your code in the On Current event of the Form to allow for when the Form loads or a different record is selected.

If me!IsTrue = True Then
me!OnlyIfIsTrue1.Visible= True
me!OnlyIfIsTrue2.Visible= True
Else
me!OnlyIfIsTrue1.Visible= False
me!OnlyIfIsTrue2.Visible= False
End If
 
Thanks guys, that really helped. I did have to put the code in both the On Current event of the form and the After Update event of IsTrue in order for it to work under any combination of events between the opening of the form and the checking/unchecking of the box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top