Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

disabling all controls on a form save one

Status
Not open for further replies.

DHSBW

Technical User
Jan 23, 2007
11
US
I want to disable all controls on a form open event execept of the textbox Employee ID. Is there some loop procedure I can use to accomplish that?
 
I also do this sometimes...Here is the code that I use

Code:
Dim ctl As Control
For Each ctl In Me.Form
   If not ctl.Name Like "MyExcludedControl" Then
        ctl.enabled = false
   End If
Next ctl

Of course, you cannot disable a control that has focus, so make sure that you set your focus to the control that you will leave enabled.
 
How are ya DHSBW . . .

Since you want this to occur when you first open the form why not [blue]disable the controls (default) in design view[/blue] and save yourself the code? . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
AceMan - I assume that at some point he'll want to enable the controls (else why have them) so either way he will need the looping code (either to enable or disable).

 
Hi:

Thanks for responding. I found an example from another site. Sorry I didn't get back sooner. Posted the code below just for the hell of it.

Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
For Each ctl In Me.Controls
Select Case ctl.ControlType
Case acTextBox
If ctl.Name Like "*Emp" Then
ctl.Enabled = True
Else
ctl.Enabled = False
End If
End Select
Next
Me.Emp.SetFocus
End Sub
 
Howdy JoeAtWork . . .

Yes they'll have to be turned on but it saves the following:
DHSBW said:
[blue]I want to disable all controls on a form open event execept . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top