Private Function disableAllbut()
Dim ctl as control
For each ctrl in me.Controls
if ctl.ControlType=acTextbox or ctl.ControlType=accheckbox Then
If ctl.Name <> " chkbox1" Then
ctl.Enabled = Nz(Me.chkBox1.Value,False)
End If
End If
Next
End Function
Set all of your controls to Disabled (or whatever you want), then use the GotFocus event of each control to enable it:
Sub <YourControl>_GotFocus()
Me.Controls("YourControl").Enabled = True
End Sub
Then use hte LostFocus event to disable it:
Sub <YourControl>_LostFocus()
Me.Controls("YourControl").Enabled = False
End Sub
You'll have to do this on EVERY control, however, which can be a real PITA.
If they are all disabled but chkbox1, then what do you expect to accomplish on that form?
Sidenote...all the above codes (except mine and Scott's )will fail due to the fact that checkBoxes come with a default value of Null...
Sidenote...all the above codes (except mine( will fail due to the fact that checkBoxes come with a default value of Null...
Mine won't ...
Mine won't ...
Sry Sott i missed that you put the value hard coded.... i almost never do that's why i missed it. ...i corrected it in the previous post
arana,
if he checks in chkBox1, and all other controls are disabled, then what can he possibly do? All of the other controls are now disabled.
arana,
Let the OP answer for himself, please. Generally you might disable some controls, but I cannot think of a single use case where you want to disable every other control on a form if a checkbox is checked. I could understand locking all of the data controls, but not disabling every control.
Dale
Open in new window
Depending on what you are doing you might want to use
Open in new window