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.