Enabling Multiple Controls

R

Rob

Hello All,

Is there a way to enable and disable all controls on a form via VBA?

Thanks,

Rob
 
K

Ken Snell \(MVP\)

Yes, though one must ask, why such a brute force approach?

You can loop through all the controls in a form this way:

Dim ctl As Control
For Each ctl in Me.Controls
On Error Resume Next
ctl.Enabled = True ' to enable
Err.Clear
Next ctl

But, perhaps you can just set the AllowEdits property of the form to True or
False as a much easier approach?
 
R

Rob

Ken,

What I want is to make sure that the user always clicks on my New button to
create a new record. If the controls are not enabled then the user would be
forced to select the New or Edit button to gain access to the controls. If I
set the AllowEdits property to false the user can still click on the
controls. My New button does some other things in linked tables and I need
to make sure that these things are done. I usually have form open in a new
record but then those commands would not fire until the next new record is
created leaving the current one without some support data needed to be
created in other tables.

Thanks for the help. That will work fine.
 
M

magicdds

I have a similar question:

Is there a way , from a command button on FORM1, to check which other forms
are open, and set the ENABLED property of each of those forms to NO?

Thanks
Mark
 
L

Linq Adams via AccessMonster.com

Dim ctl As Control
For Each ctl in Me.Controls
On Error Resume Next
ctl.Enabled = True ' to enable
Err.Clear
Next ctl

I've never seen error suppression done like that, for this kind of hack, Ken!
I've always looped, checking the type of each control to make sure that they
had the given property before setting it, to avoid errors. Much easier this
way! I'll file it away in my arsenal!

Linq
 
L

Linq Adams via AccessMonster.com

Is there a way , from a command button on FORM1, to check which other forms
are open, and set the ENABLED property of each of those forms to NO?

Forms have no Enabled Property!
 
K

Ken Snell \(MVP\)

It's called being "lazy"..... or just short on time.... ! < grin >

Nothing wrong with what you do in your code... I do that in other situations
for various reasons. And it's a "cleaner" way to develop.
 
Top