"Property or Control Not Found" Using Form/Control Data Type

ID Number: Q84383

1.00

WINDOWS

Summary:

You do not need to prefix a control name with the parent form name

when you are accessing the property of a control from a Sub or

Function to which the control is passed as a parameter. If you use the

syntax

form.control.property

to access the property of the control, you will get a "Property or

Control not found" error.

This information applies to Microsoft Visual Basic programming system

version 1.0 for Windows.

More Information:

The full syntax to access a property of a control on a form is as

follows:

form.control.property

If the control whose property you are accessing is on the form where

the code resides, you do not need to prefix the control name with the

form name. For example, if command button Command1 is on Form1 and you

want to set its Enabled property to False (0) in the event procedure

Command1_Click, you can use the following:

Command1.Enabled = 0

You can use the same syntax if the statement is in the general

Declarations section of Form1. However, if you want to access the

Enabled property of Command1 on a form other than its parent form, or

from a Sub or Function in a module, you need to use the full syntax

(with the form name).

The property of the control can also be accessed in a module by using

the full syntax. For example, to disable Command1 (which is on Form1)

in MODULE1.BAS, add the following:

Sub AccessProperty

Form1.Command1.Enabled = 0

End Sub

However, if you are passing the control as an argument to a Sub or

Function procedure in a general module, you do not need to use the

full syntax. For example

Sub AccessProperty (ThisForm as Form, ThisControl as Control)

ThisForm.ThisControl.Enabled = 0

End Sub

will give you a "Property or Control 'ThisControl' not found" error.

You only need to pass the control name as an argument to the

procedure. For example:

Sub AccessProperty (ThisControl as Control)

ThisControl.Enabled = 0

End Sub

Additional reference words: 1.00