Setting all controls in a Form

D

DaveAlfa

Hi,

i've got a form & would like to set all the Textboxes in a form
Enabled=False is the recorded as marked as locked. ( i have a boolean file
for each record).

instead of listing each textbox.enabled = false, can i write a short loop
routine to set all the textbox fields in to form to enabled = false ?

thanks

Dave
 
R

Rick Brandt

DaveAlfa said:
Hi,

i've got a form & would like to set all the Textboxes in a form
Enabled=False is the recorded as marked as locked. ( i have a boolean
file for each record).

instead of listing each textbox.enabled = false, can i write a short
loop routine to set all the textbox fields in to form to enabled =
false ?

thanks

Dave

What I typically do...

Give all controls you want to toggle a common Tag property entry (like
"Enable"). Then use code to loop through them...

Dim cnt as Control

For Each cnt in Me
If cnt.Tag = "Enabled" Then cnt.Enabled = False
Next cnt

This allows you to easily select all the controls you want to change as well
as to ignore those that you don't want to change.
 
F

fredg

Hi,

i've got a form & would like to set all the Textboxes in a form
Enabled=False is the recorded as marked as locked. ( i have a boolean file
for each record).

instead of listing each textbox.enabled = false, can i write a short loop
routine to set all the textbox fields in to form to enabled = false ?

thanks

Dave

Dave,
I have no idea what to make of this part of your message:
" ... is the recorded as marked as locked. ( i have a boolean file
for each record)."

Anyway, yes! You can cycle through the controls. Where you would place
the code depends upon when you wish to set them to Enabled = False.

Let's assume it's when the form opens.
Place the following in the Form's Load event:

Dim c as Control
For each c in Controls
If TypeOf c is TextBox then
c.Enabled = False
End If
Next

The above change is not carried over to the next session, unless you
do it in design view and save the changes.
 
D

DaveAlfa

thanks ... that's what exactly wanted!! both suggestions worked fine, though
for the tag i had to mark all Text fields with the same tag.

my problem is that when i declared 'Dim cnt as control', then when writing
'cnt.' the 'Tag property is not suggested by VBA though it is accepted. Thus,
i did not know that i could use this property. i found that a number of
properties are not suggested by VBA.
 
Top