Calling methods of .ocx controls at runtime
Hi,
I wanted to load the .ocx controls at runtime and call its methods during runtime.
I was able to load the control at runtime but not able to set its methods and subroutines.
Here is the code snippet:
Dim WithEvents objEcg As VBControlExtender
Private Sub Form_Load()
Set obj = Controls.Add("ProgID.OCXCtrl", "ocx1", Frame1)
obj.Visible = True
obj.WebURL = "URLPath"
obj.Height = 375
obj.Left = 120
obj.Top = 240
obj.Width = 300
Call obj.methodOnOCX("strparam1", "strparam2")
End Sub
Note: methodOnOCX is a subroutine with signature as methodOnOCX(str1 as String,str2 as String)
Error on calling the function is: "Object variable or with block variable not set"
Note: I am able to set all the properties of the control and view them during runtime.
Any help is appreciated.
Thanks
Re: Calling methods of .ocx controls at runtime
Is methodOnOCX a Public method? Private & Friend declarations should fail. Additionally, if it is public, are you sure the error is coming from that call or could the error be coming from within the OCX? That may be a possibility.
Re: Calling methods of .ocx controls at runtime
No, the method is a public method. If the ocx control is added during runtime itself, the method runs fine. So, I don't think there is any error in the method.
Re: Calling methods of .ocx controls at runtime
Sorry it took a bit. I think this might work. precede your methods with the word Object, like so....
Call obj.Object.methodOnOCX("strparam1", "strparam2")