Visible property is variable?

CedarTree

Registered User.
Local time
Today, 00:24
Joined
Mar 2, 2018
Messages
438
Hello - I want to have a primary subform and then based on what a specific data field within that form is, e.g., "project type", have another subform appear or disappear. So, for example, if project type = "quantum mechanics" (QM), then QM subform would be visible. But if project type = "Time travel" (TT), the TT subform would be visible, and the QM subform would not. Any tips/tricks to do this? I was thinking to have a function fnFormVisible that would either be true or false and would key off Project Type. Thanks!
 
Have you considered just using a Tab Control to isolate multiple subforms? Otherwise, yes you can either hide or display the affected subforms or simply use one subform control and just assign the appropriate Source Object based on project type.
 
One trick will be in writing a little snippet of VBA code to test your project type and set or clear the .Visible property as needed. Trick #2 will be to decide WHERE to put the snippet. If your project type field is on the main form, then a possible place would be in the main form's Form_Current event handler. If you do that, it takes effect when you navigate or when you save the data of the main form (both of which trigger _Current events.) If you want that visibility change to take effect the moment you make the change, then it depends on what type of control holds this project type field. If it is a combo box or list box, the control_Click event would do nicely since you have to click the combo or list to make the selection. If it is a simple text box, that becomes trickier. In that case, I have successfully used the _LostFocus event.
 
So, on_current was my thinking as well... the Project Type won't be changing (thankfully) -- but when someone navigates to a different project type, the on_current should work. Unfortunately, the Visible property I can't directly set to be equal to a boolean type function. Ah well...
 
So, on_current was my thinking as well... the Project Type won't be changing (thankfully) -- but when someone navigates to a different project type, the on_current should work. Unfortunately, the Visible property I can't directly set to be equal to a boolean type function. Ah well...

Really? What are the possibilities? 0 & 1, T/F, Y/N ??? When I look up SubForm control properties and look at Visible, it says it is a Boolean. You should be able to set the Subform.Visible property to CBOOL(some-value-or-expression). Were you setting another object to be visible or not?

 
You need a select Case statement that includes an entry for each type of subform. You need to call the procedure with the Case statement from the form's Current event and from the AfterUpdate event in case the type was changed. If you have code that prevents the type from being changed then use the AfterInsert event as the second place to call the code from to catch new record values.
 

Users who are viewing this thread

Back
Top Bottom