devxlogo

Constituent Controls are Private to UserControl Modules

Constituent Controls are Private to UserControl Modules

You cannot directly access constituent controls on a UserControl component from another module of the sameproject. Constituent controls behave differently from controls on forms, which you can access from any othermodule using the familiar “Form1.Text1” syntax. If you need to work around this limitation, have eachUserControl component expose its controls using a Friend property.For instance, if the UserControl1 module needs to expose one of its constituent controls, add this propertyprocedure:

 Friend Property Get TextControl() _        As TextBox                Set TextControl = Text1End Property

When you wish to modify the Text property of the control of a particular instance of UserControl1 in the BASmodule, write something like this:

 Sub ClearText(uc As UserControl1)        uc.TextControl.Text = ""End Sub

devx-admin

Share the Post: