Managing many controls on a form in code (Leo asked)

L

Leo

Hi helpers,
I have a single form with many controls, which acts like a dialog for
settings criteria for many different reports. (instead of giving each a form
for asking criteria).
Based on the requesting command button on switch board, by the "OpenArgs" of
this form, I like to activate a certain group of controls, suiting the
requested report for asking user for its criteria , and other controls should
be disabled and invisible.
I tried it with "Control" object, but it could not help.
Is there any way to loop through all controls of the form, and based on the
OpenArgs Value of the form, and tag or name of the control, disable control?!
 
M

missinglinq via AccessMonster.com

Not sure exactly what you're trying to do, but I think this is the general
mechanism you need. You can use the same routine to make controls
Visible/Invisible, change their colors (when Access allows) and so forth. In
this particualr routine, if the OpenArgs is set to "Marked" then all controls
so Tagged will be enabled.

'Set all controls to Disabled as default
'Set the Tag Properties of the controls you want disabled to "Marked"
(without the quotes)

Private Sub Form_Load()

If Me.OpenArgs = "marked" Then
Dim ctrl As Control

For Each ctrl In Me.Controls
If ctrl.Tag = "marked" Then
ctrl.Enabled = True
End If
Next

End If
End Sub

You don’t have to use this code in Form_Load, of course. You could use it in
the BeforeUpdate sub for a checkbox or other object. And you can also have
multiple levels within a form, i.e. several different Tags being used to
identify different groups of controls to be disabled/enabled.
 

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