Full Version: Unavailable Controls
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Lola28
I have a database where I keep track of information for all employees active and non active. I have a column called active with a yes/no combo box. I would like ALL of the values on a form to be dimmed (unavailable) if the value of that one control is No. I have a book that I ordered that makes me think that I can do this but doesn't expalin how.
Paul_Churchill
In Access help search for "Conditional Formatting"

You can certainly change the format- colour background typestyle etc for the controls based on the condition of your yes/no field - I'm not sure if A2002 conditional formatting can actually disable those rows (I doubt it but I may be wrong)

Regards
Paul Churchill
Lola28
I could certainly do that if that is all that is available to me but I don't know how to do that either.
NoahP
You'll have to use VBA code to do this. From Design View:

1) Select all the controls that need to be enabled/disabled.
2) Open the Properties Window, and set the Tag Property (On the Other Tab) to ED (ED is just short for enable/disable. You can set it to whatever you'd like as long as you change ED later in what I suggest to whatever you change ED to in the Tag Property) for every control you want to enable/disable
3) In the On Current Event of the Form, select [Event Procedure] and left click the ellipsis (...) to the right of your selection
4) In the code window, place:

CODE
Dim ctl As Control

For Each ctl in Me.Controls
  If ctl.Tag = "ED" and (ctl.controltype = acTextBox Or  ctl.controltype = acComboBox or _
    ctl.ControlType = acListBox) Then
    ctl.Enabled = Me.Active
  End If
Next ctl


That loops through all textboxes, combo boxes and listboxes with a Tag Property of ED and enables/disables them according to the value in the field Active.
Paul_Churchill
OK


the column "Active" is that the name of the control on your form or the data field in the controls data property I need the latter

and pleas give me the name of one of the controls that you want to disable and Ill talk you through it

Paul
Lola28
Active is the name of the control and is the control source.
A name of one of the controls that I want to disable is: Name
Lola28
Noah P. I got an error when I tried your way. I am sure that I did something wrong.

Complile error:
Expected: In

The "=" just before the "ED" was highlighted.
I have never done anything like this before so I would not be suprised if I made a silly error. Below I copies whta my screen looked like.

Private Sub Form_Current()
Dim ctl As Control
For Each ctl.Tag = "ED" and (ctl.controltype = acTextBox Or ctl.controltype = acComboBox or _
ctl.ControlType = acListBox) Then
ctl.Enabled = Me.Active
End If
Next ctl

End Sub

Edited by: Lola28 on Thu Apr 5 12:37:19 EDT 2007.
NoahP
You didn't copy and paste exactly.

It should be

For Each ctl in Me.Controls
If ctl.tag="ED"...

You left out the "ctl in Me.Controls
If "
Lola28
Thank you - I will try again.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.