PRB:Property or Control Not Found Error Passing Control to Sub

Last reviewed: June 21, 1995
Article ID: Q84383
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SYMPTOMS

Using form.control.property to access the property of a control causes a "Property or Control not found" error.

CAUSE

The control was passed to the Sub or Function procedure incorrectly.

RESOLUTION

To reference a control in a Sub or Function procedure, do not pass the form and then the control; just pass the control. Then once you pass the control to the Sub or Function procedure, do not prefix the control name with the parent form name when accessing a property of the control inside the Sub or Function procedure.

MORE INFORMATION

How to Pass a Control to a Sub or Function Procedure

To pass a control to a Sub or Function procedure, provide the parameter by specifying Formname.Controlname or just Controlname as in this example:

   Sub Test(x As Control)
      X.Caption = "hello"
   End Sub

   Call Test(Form1.Label1)

   -or-

   Call Test(Label1)

Either way, the appropriate information is passed to the Sub procedure. How you call it depends on where you call it.

How to Pass a Form to a Sub or Function Procedure

When you pass a parameter As Form, the Sub procedure expects the item following the form variable to be a property of that form object:

   Sub Test(x As Form)
      X.Caption = "hello"
   End Sub

   Call Test(Form1)

The item that follows X must be a property of the form variable X.

Referencing a Property of a Control When the Control is Not Passed

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

   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 a Command1 control that resides on a form other than its parent form, or if you want to access that property from a Sub or Function procedure in a module without passing the control to the procedure, use the full syntax with the form name.

For example, to disable Command1, which is on Form1, in MODULE1.BAS, add the following code:

   Sub AccessProperty
      Form1.Command1.Enabled = 0
   End Sub


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode kbprb
KBSubcategory: APrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.