Getting a Reference to a VB?á5.0 UserControl

By | 2002-06-01

Visual Basic 5.0 allows you to use UserControls to create ActiveX controls in your projects. The following code snippet does two things: It gets a reference to the form in which a UserControl is placed, and it gets a reference to that control on the form. by David Mendlen

Original Author: Found on the World Wide Web

Code


Dim PControl As Object
Dim MyControl As Control
Dim AControl As Object
'Get my UserControl
For Each AControl In ParentControls
  If AControl.Name = Ambient.DisplayName Then
    Set MyControl = AControl
    Exit For
  End If
Next
'Get the Form UserControl is on
Set PControl = ParentControls.Item(1).Parent
While Not (TypeOf PControl Is Form)   Set PControl = PControl.Parent
Wend

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.