Form control properties like Enabled and ControlType are invisible

G

Guest

I want to refer to a form control's property (in Access 2003 VBA) such as
Enabled or ControlType. I enter the code and it works fine, but I have to
know Access will accept them - I'm not prompted by Access with the available
options as is usually the case. For example:

Dim ctl AS ctl
For Each ctl in Me.Controls
ctl.Enabled = True
Next

When typing the third line, I would expect to be prompted after entering "."
with all available options but I don't - I get some. Certainly I don't get
Enabled or ControlType. I would like to know why they don't appear in the
menu of options. Do I need to reference some other Object Library (I
currently have references to the Office 11.0, Access 11.0, DAO 3.6, ActiveX
Data, OLE Automation and VBA object libraries)? Your advice will be
appreciated.

Don
 
A

Allen Browne

Presumably the first line reads:
Dim ctl As Control

Control is a very generic object type. Some controls (such as lines and
labels) don't have an Enabled property. At design time, Access is unable to
determine what control(s) the loop will refer to, and therefore doesn't know
what properties to offer you.

You can go ahead and use the Enabled property if you wish. The code will
compile, but it may fail at runtime if some controls don't have the
property.

Where you do need to work with properties that may not apply, my preference
is to test that in a separate routine rather than try to handle the error in
the main procedure. There's a simple little HasProperty() function at the
end of this page:
http://allenbrowne.com/AppPrintMgtCode.html#HasProperty

One of the other curiosities is that the Visible property doesn't always
show up in the Intellisense lists either, even though almost every control
does have a Visible property.

Where practical, it helps to be more specific about the type of control you
are referring to, e.g.:
Dim txt As Textbox
 
G

Guest

Thanks Allen

Allen Browne said:
Presumably the first line reads:
Dim ctl As Control

Control is a very generic object type. Some controls (such as lines and
labels) don't have an Enabled property. At design time, Access is unable to
determine what control(s) the loop will refer to, and therefore doesn't know
what properties to offer you.

You can go ahead and use the Enabled property if you wish. The code will
compile, but it may fail at runtime if some controls don't have the
property.

Where you do need to work with properties that may not apply, my preference
is to test that in a separate routine rather than try to handle the error in
the main procedure. There's a simple little HasProperty() function at the
end of this page:
http://allenbrowne.com/AppPrintMgtCode.html#HasProperty

One of the other curiosities is that the Visible property doesn't always
show up in the Intellisense lists either, even though almost every control
does have a Visible property.

Where practical, it helps to be more specific about the type of control you
are referring to, e.g.:
Dim txt As Textbox
 

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