Form Objects

  • Thread starter Thread starter Jay Bukstein
  • Start date Start date
J

Jay Bukstein

When a listbox is clicked I'm trying to set the Other
object properties to false. In my code I loop throw all
the controls with this code:

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType <> acListBox Then
ctl.Enabled = False
End If
Next ctl

But when I try to run this code I get an error of Object
doesn't support this method. But this is almost
identical to the Help file example.

The big difference is:

with ctl
.Enabled = False
end with

This alos doesn't work, Any Ideas.
 
A number of Controls don't have the Enabled Property, for example Label
Control. You need to filter them out and only refer to the Enabled Property
of the Control if the Control actually has the Enabled Property.

Alternatively, you can try to set the Enabled Property regardless but make
sure you trap and ignore the error. Something like:

***untested air-code****
For Each ctl In Me.Controls
If ctl.ControlType <> acListBox Then
On Error Resume Next
ctl.Enabled = False
End If
Next ctl
'(set back to your normal error-trapping)
****
 
Back
Top