Form Objects

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.
 
V

Van T. Dinh

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)
****
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top