HOW TO: Pass Form/Control Objects to ActiveX Control 
Author Message
 HOW TO: Pass Form/Control Objects to ActiveX Control

VB won't let me use form or control arguments in my ActiveX control that are
to be passed through procedures (apparently by design).  So how do I get
around this?  My goal is to have my ActiveX control manipulate other
controls on the parent (or host) form.  I also can't seem to get the ActiveX
control to reference the parent property with an success.

Can anyone help?  Thanks.



Sun, 27 Jun 2004 12:52:19 GMT  
 HOW TO: Pass Form/Control Objects to ActiveX Control
Well, found something I think.

I can do this:

Dim varItem as Variant

For Each varItem in UserControl.ParentControls
    If varItem.Name = "Name of control I'm looking for" Then
        Msgbox "Found Control"
    End If
Next varItem

NOTE:  I used a variant instead of a Control object, simply because VB
wouldn't let me do it any other way.



Quote:
> VB won't let me use form or control arguments in my ActiveX control that
are
> to be passed through procedures (apparently by design).  So how do I get
> around this?  My goal is to have my ActiveX control manipulate other
> controls on the parent (or host) form.  I also can't seem to get the
ActiveX
> control to reference the parent property with an success.

> Can anyone help?  Thanks.



Sun, 27 Jun 2004 13:15:15 GMT  
 HOW TO: Pass Form/Control Objects to ActiveX Control
You can declare the parameters As Object to pass forms/controls between
components, e.g.:

Public Sub SetFormCaption(ByVal FormObj As Object, ByVal Caption As String)
    Dim frmTemp As Form
    If TypeOf FormObj Is Form Then
        Set frmTemp = FormObj    'not necessary, just for intellisense
        frmTemp.Caption = Caption
    Else
        Err.Raise 9, "SetFormCaption", "Type mismatch: required Form."
    End If
End Sub

Is this what you were looking for?

HTH-Jon



Quote:
> VB won't let me use form or control arguments in my ActiveX control that
are
> to be passed through procedures (apparently by design).  So how do I get
> around this?  My goal is to have my ActiveX control manipulate other
> controls on the parent (or host) form.  I also can't seem to get the
ActiveX
> control to reference the parent property with an success.

> Can anyone help?  Thanks.



Sun, 27 Jun 2004 20:01:53 GMT  
 HOW TO: Pass Form/Control Objects to ActiveX Control
James,

I'm not sure if I understand the problem you are having.  I agree that you
_cannot_ pass a form or control to your usercontrol via a public procedure.
However, I don't have any trouble at at ref'ing the Usercontrol.Parent
property.  In my case, I just created little sample control and set a form
ref equal to "Usercontrol.Parent".  I was then able to do whatever I needed
to the form using the private form.  Here's my sample code:

Option Explicit

Private mForm As VB.Form

Private Sub UserControl_Click()
    Debug.Print UserControl.Ambient
    Set mForm = UserControl.Parent
    MsgBox mForm.Name & " has a helloworld control"
End Sub

As far as coding which other control on the form to mess with, you can pass
it in your public usercontrol proc as a string and fish it out of the form
from inside the usercontrol.  Seems like there would be an easier/"more
natural" way but I haven't found it yet.

Simon Taylor
Resource Data, Inc.



Quote:
> Well, found something I think.

> I can do this:

> Dim varItem as Variant

> For Each varItem in UserControl.ParentControls
>     If varItem.Name = "Name of control I'm looking for" Then
>         Msgbox "Found Control"
>     End If
> Next varItem

> NOTE:  I used a variant instead of a Control object, simply because VB
> wouldn't let me do it any other way.



> > VB won't let me use form or control arguments in my ActiveX control that
> are
> > to be passed through procedures (apparently by design).  So how do I get
> > around this?  My goal is to have my ActiveX control manipulate other
> > controls on the parent (or host) form.  I also can't seem to get the
> ActiveX
> > control to reference the parent property with an success.

> > Can anyone help?  Thanks.



Mon, 28 Jun 2004 02:11:14 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Passing a control object to ActiveX control?

2. Passing Objects to ActiveX Control

3. Passing info between form and ActiveX control

4. Passing a form to an activex control

5. Pass activex control to another form

6. How to pass a VB intrinsic Control as parameter to an ActiveX control (UserControl)

7. ActiveX control with a Form object

8. Intancing ActiveX Control without form object

9. Passing ActiveX control as a parrameter to ActiveX.dll

10. Accessing a public function within an ActiveX control from a form created by the control

11. Removing ActiveX Control and other ActiveX objects from the registry

12. Accessing activex control from another activex object in ie5 (vb 6)

 

 
Powered by phpBB® Forum Software