Possible to reference controls by Tags?

D

Doctor

Is it possible to reference controls on a form by their tag? I saw something
once that made me wonder if this was possible.

I have two divisions that work off of the same database. Some of the
controls don't apply to the other part of the users. Can I assign a tag,
Group1, to some controls, and Group2 to another group of controls? If so here
is what I would like to do in the Open event of the form

If usergroup is Group1 Then Set all controls with tag Group2 to .visible =
false.

First is this possible; second, what would be the syntax? I am imagining
something like a For Each ctl kind of deal.

Thanks in advance
 
D

Douglas J. Steele

Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If Usergroup = "Group1" Then
ctlCurr.Visible = (ctlCurr.Tag <> "Group2")
End If
Next ctlCurr
 
D

Doctor

Perfect.

Douglas J. Steele said:
Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If Usergroup = "Group1" Then
ctlCurr.Visible = (ctlCurr.Tag <> "Group2")
End If
Next ctlCurr
 
T

Tony Toews [MVP]

Douglas J. Steele said:
Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If Usergroup = "Group1" Then
ctlCurr.Visible = (ctlCurr.Tag <> "Group2")
End If
Next ctlCurr

I prefer using Instr in case I decide I need multiple options to be
kept in the control tag. Which, admittedly, doesn't happen often.

And the above code would be different.

Tony
 
D

Douglas J. Steele

Tony Toews said:
I prefer using Instr in case I decide I need multiple options to be
kept in the control tag. Which, admittedly, doesn't happen often.

And the above code would be different.

Valid point.

Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If Usergroup = "Group1" Then
ctlCurr.Visible = (InStr(ctlCurr.Tag, "Group2") = 0)
End If
Next ctlCurr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top