Microsoft KB Archive/235414

= PRB: ParentControls Property May Not Work with Some Containers =

Article ID: 235414

Article Last Modified on 1/11/2001

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q235414



SYMPTOMS
The ParentControls Collection of a Visual Basic UserControl is empty when the control is placed in a non-Visual Basic Container.



CAUSE
The ParentControls property is designed to return a Collection of all the controls situated on a Form, UserDocument, or other UserControl. This property is exposed by the Visual Basic extender object, and it is the responsibility of the host container to implement the code needed to fill the collection. Not all containers will support this feature. Consequently, this property might return an empty collection in containers that do not support it.



STATUS
This behavior is by design.



Steps to Build Control
 Start Visual Basic and select New ActiveX Control. UserControl1 is created by default. Change the name of the UserControl1 to MyControl and the Project name to MyControlServer.  Place a listbox and a CommandButton on the control, and in the click event of the CommandButton, put the following code: List1.Clear Dim x As Object For Each x In UserControl.ParentControls List1.AddItem x.Name Next  Save the project and compile to build an OCX.

Steps to Create a Visual Basic Container

 * 1) Start Visual Basic and select New Standard EXE. Form1 is created by default.
 * 2) Place a few controls on Form1. (The type of controls is not important.)
 * 3) From the Project menu, select Components. From the Components list, select MyControlServer to add your custom control to the control toolbox.
 * 4) Insert an instance of this control on Form1.
 * 5) Run the project by pressing the F5 key. When you click on the CommandButton of MyControl1, the list box will be filled with all the names of the controls on Form1 (including your custom control).

Steps to Create a Visual Basic for Applications Container

 * 1) Start Microsoft Word and go to the Visual Basic Editor (ALT+F11).
 * 2) Insert a UserForm in your project.
 * 3) Place a few controls on the form. (The type of controls is not important.)
 * 4) Click the right-mouse button on the Toolbox Controls and select Additional Controls.
 * 5) Select MyControlServer.MyControl from the list.
 * 6) Insert an instance of this control on the form.
 * 7) Run the form and click on the CommandButton of your custom control. You will notice that the list box is not filled because the ParentControls Collection is empty. The Collection is empty because VBA does not implement this property.

Keywords: kbctrlcreate kbprb KB235414

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.