Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling functions between UserControl and forms

Status
Not open for further replies.

leyann

IS-IT--Management
Sep 16, 2002
29
FR
Hi,
I've got a UserControl component and a form in my project. I'd like to call functions defined in my UserControl from my form... but vb can't find the UserControl.
How could I do ?
 
Hi,

Subs, functions & properties that are declared as 'public' is available as methods and properties of you usercontrol.

1) open a new exe project
2) add a new (file menu) usercontrol project.
3) add a public sub to the usercontrol and close the usercontrol design window.
4) drop an instance of you usercontrol to you exe form and test that ".YourPublicSub" is a method of your usercontrol (which be default is named usercontrol11).
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Thanks for your answer.

Th problem is that I don't want to create a new exe project but an activeX control project... so dropping an instance of my usercontrol on my form seems to be impossible.

Is there another possibility ?
 
What can be done is :
Set myUserControl = CreateObject "myProjectName.UserControlName")

and then call :

Call myUserControl.myFunction(parameters)

... but I don't think it is actually a nice solution. Moreover, it seems to create a new instance of my usercontrol object, so I can't access to the existing objects of the main usercontrol object (did you follow me ?)
 
Why do you have a form in your ActiveX .ocx project - is the form instantiated by the UserControl? If so, why not pass a 'Me' type object reference from the User Control to the form just after you instantiate it?

ie...inside your usercontrol..
Dim oFrm as MyForm
set oFrm = new MyForm
oFrm.Display(Me)


and inside your form "MyForm"...

private moParentControl as MyUserControlName

public sub Display(byval oParent as MyUserControlName)
set moParentControl = oParent
me.show vbModal
end sub

Cheers,
Grant.
 
I like this last answer.
Thanks a lot.
But unfortunaly, I don't know how to do it : the type "MyUserControlName" is not known in my form (I don't know why). So :
private moParentControl as MyUserControlName
is ineficient.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top