grouping controls

Luciano

Registered User.
Local time
Today, 14:33
Joined
Jul 29, 2007
Messages
25
Hi, I want to disable in VBA (.enabled = false) a lot of controlls, depending of some conditions. Is it possible to group (and having an unique name)these controlls to disable them all together at the same time.
 
I'm not the best to answer this but how about a For Next loop.
I have controls called FR1, FR2, FR3, FR4, FR5. To loop through and change them, I use this;
For i = 1 To 5
Me.Controls("FR" & i).Enabled = False
*more code here
Next i

Don't forget that you'll need code to enable them also.
 
Indead, it would be a valid solution, but it's quit impossible for me to rename these controls (I use many prefixes like txt, chk, cmd, fra, ...).
 
It is not really possible to group controls in the way you might want. However, I have had to deal with this same type thing over the years and have come up with what I thing is a good method for accomplishing the desired results.

I utilize the "tag" property of each control that I need to manage. For each control that I want to "disable" or "enable" I put "SetEnabled". I do the same for controls that I want to have be visible by putting "SetVisibility". I use the same idea for controls that I want to "Lock" by putting "SetLocked" in the tag property. I then use a public function that I have written that evaluates these values in my form or sub form and sets or changes the various values of each control when the function is called.

Here is a link to a demo that will provide you with examples of this method. The public function is in the demo.
http://www.askdoctoraccess.com/DownloadPage.aspx
Down load the "ManagingMultipleControls.zip" file, unzip it an give it a try.

Hope this helps.
 
On the same way, you can use the TAG property.
Set the .tag property to the same value then use a cycle to enable/disable the controls that have the same tag:
Code:
Dim ctl As Control
For Each ctl in Controls
    If ctl.tag = "CommonTags" Then
       ctl.Enabled = True/False
    End If
Next ctl
Note, please, that this is an "in air" code. So, maybe, is necessary to tweak it a little bit.
Good luck !
 
I think this is the perfect solution for my problem. Thank you very much.
 
BTW, to set the Tag Property for multiple Controls, all at once:
  1. Go into Form Design View
  2. Holding down <Shift> and Left clicking on each Control in turn.
  3. Go to Properties – Other and enter your value in the Tag Property
Linq ;0)>
 
Also worth noting is the fact that you can have multiple groups, each with its own unique Tag, and even include Controls that appear in both groups!

Given that you have two groups of Controls you want to format, depending on a condition:

Group1
ControlA
ControlB
ControlC


Group2
ControlA
ControlX
ControlY
ControlZ


Notice that ControlA is part of both groups, so you'd set its Tag Property as

Group1 Group2

If you want to do something to the Controls in Group1, you'd now use:

Code:
Dim ctl As Control
For Each ctl in Controls
    If InStr(ctl.tag, "Group1") > 0 Then
       ctl.Enabled = True/False
    End If
Next ctl
Likewise, to loop through the Controls in Group2:

Code:
Dim ctl As Control
For Each ctl in Controls
    If InStr(ctl.tag, "Group2") > 0 Then
       ctl.Enabled = True/False
    End If
Next ctl
Now, whether you want to work with Group1 or Group2, ControlA will be included!

Linq ;0)>
 
Glad to help you.
I must ask Mr.B to forgive me :) because I give the same solution as he.
But... I started to answer then my dog "asked" me to go out. And he "say": NOW.
When I returned I continued the answer and I post it. Only at that time I saw Mr.B answer.
 
Since the OP already has a solution this is for interest only...

You can group controls. You can do this by using the tab control.

Setting the Style of the tab control to None removes the tabs and then setting the back style to transparent makes the control "invisible" so the user is not aware that a tab control is being used. Add the controls you want to group to the tab page.

The code for iterating your controls in the tab control is:
Dim ctrl As Control
For Each ctrl In Me.myTabPage.Controls
'your code to change the control here
Next

You can have several tabs/groups.

Chris
 
Last edited:

Users who are viewing this thread

Back
Top Bottom