Possible to reference controls by Tags?

  • Thread starter Thread starter Doctor
  • Start date Start date
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
 
Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
If Usergroup = "Group1" Then
ctlCurr.Visible = (ctlCurr.Tag <> "Group2")
End If
Next ctlCurr
 
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
 
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
 
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
 
Back
Top