Referencing Forms elements from custom Controls

OK.. I'm new in VB... I need a way to say make a text box display a message (from a database or any source for that matter)by clicking on a command button from within my own control... So how do you access the command button on the form from the custom control... thanx
lamer2Asked:
Who is Participating?
 
peterwestConnect With a Mentor Commented:
Hi,

Ok then - you could use the ParentControls property of the ActiveX object but this uses an object index to specify which object you want to access; this is obviously a little fiddly - an easier way is like this:

Private Sub Command1_Click()

      UserControl.Parent.Text1.Text = "Hello World"

End Sub


Just as you can prefix a property with an object you can also prefix an object with a form.  In this case we use the Parent property of the UserControl to get a reference to the parent form and then we can modify the textboxes property.

Hope this helps,

Pete

0
 
lamer2Author Commented:
when i kinda figure it out myself...

I noticed that typing

parent.text1 = "bla bla does the same thing"
0
All Courses

From novice to tech pro — start learning today.