Hiding/Un-hiding Form Controls with a Module

You hit the nail right on the head. Others will be using this db and I do take a lot of pride in my work. I love that saying about knowing where the machine's power cord is plugged in! I will have to drop that one sometime and see what response I get!

Thanks again for the guidance.
 
ridders, I have tagged all my controls "A" for always visible, and then tagged the ones I want to hide as "T2". I have copied both of your modules over to my db, but it still does not hide the controls. It has however stopped hiding random other controls. So that issue is resolved. Do I also need to copy over your table and the 3 queries? I am trying to figure out where the connection between my form and the modules take place.
 
ridders, I have tagged all my controls "A" for always visible, and then tagged the ones I want to hide as "T2". I have copied both of your modules over to my db, but it still does not hide the controls. It has however stopped hiding random other controls. So that issue is resolved. Do I also need to copy over your table and the 3 queries? I am trying to figure out where the connection between my form and the modules take place.

You ONLY need to copy ONE module modControlState
No tables or queries should be copied

You then need to add code to your form

In Form_Load event:
Code:
ShowControls True, "A"
ShowControls False, "T2"

Then when you later want to show T2 controls, use
Code:
ShowControls True, "T2"

However, in an earlier post you described a more complicated setup
I gave an answer in post 8 to what I thought you wanted to do
 
Last edited:
Is the SetControl function something new? Looking at your db, I do not see the SetControl function. Here is what I used from your db and I already have it on Form_Load


ShowControls True, "A"
ShowControls False,"T2", "T3"
 
Sorry. SetControls was the old name and I used it by mistake.
I will amend the earlier post.

Are you sure you have any controls tagged T2 or T3?
The method works so you must be doing something wrong.
 
So I put a control on the actual form, outside the 2 subforms, and it works perfectly with my buttons. Any of the controls inside subforms 1 & 2 does not.
 
So I put a control on the actual form, outside the 2 subforms, and it works perfectly with my buttons. Any of the controls inside subforms 1 & 2 does not.

Of course not. You have to put the subform control code in the subform itself
 
Yes, they are tagged A for all controls I want visible, and T2 for those that I want to hide. I have only tagged the T2 group for now. I still have the T3 and T4 group to re-tag. Currently they are set for A.

I am going to pull a clean db and start over. I have made so many changes that I may have messed it up. The version I am working with is the one where I was trying my code too. Now that I know about the "tag" feature, I will start over.

Just to confirm I am putting the tag in the right spot, it is the last field in the Properties box, correct?
 
It should be labeled as "Tag" in the properties box. Shouldn't be any question of what it is.
 
Ok. I am sure that I put the identifiers in the right spot. Like I mentioned, I probably butchered it up so bad that I have the form running in circles. I will start with a fresh, clean form.
 
The Tag property can't really be confused with anything else.
If you still can't solve it after making a fresh start, suggest you upload your database & I'll look at it
 
I just reworked it from a clean db and still not working. Is there a way to send it to you in a private thread?
 
Manually setting tags is a form of hard coding.
There is no reason to hard code anything in Access because you can load values from a table.

View attachment 70295

Hi Static
Yes I agree that this method works well if you have a small number of controls to handle.

However in a complex form with hundreds of controls and multiple tag values, I think it would become much more work adding all items to a table as well as taking up disk space compared to handling this via tag values
 
I just reworked it from a clean db and still not working. Is there a way to send it to you in a private thread?

Send me a PM with your email address. I'll respond with my own email.
It may take a couple of days before I will be able to look at it in detail
 
Hi Static
Yes I agree that this method works well if you have a small number of controls to handle.

However in a complex form with hundreds of controls and multiple tag values, I think it would become much more work adding all items to a table as well as taking up disk space compared to handling this via tag values

I don't know where to start... ;)
 
I too would avoid using the tag property to subset a group of controls. Rather, I would create named arrays and expose as properties, like...
Code:
private m_ctrls

Property Get MyControlGroup 
[COLOR="Green"]'  this is a variant array of controls, built on first reference, and clearly exposing
'  the group's membership
[/COLOR]   if isemtpy(m_ctrls) then m_ctrls = Array(me.ctrl1, me.ctrl2, me.ctrl5, me.ctrl9)
   MyControlGroup = m_ctrls
End Property
To hide all the controls in this group, you can use code like...
Code:
   dim ctrl as control
   for each ctrl in Me.MyControlGroup
      ctrl.visible = false
   next
To me this is much simpler and much clearer than creating subsets using Tags.
hth
Mark
 
Well, you've hard coded them, but it's still a better option.
 

Users who are viewing this thread

Back
Top Bottom