Click to See Complete Forum and Search --> : calling activex controls methods from a standard module
amitabh
Mar 17th, 2001, 01:03 AM
I am having difficulties in calling an activex controls methods from a standard module which is in the same project. If I use the code written below, I get a run time error 91 ("Object variable or With Block Not set"). But if I use the the NEW keyword, it says "Invalid use of NEW Keyword"
Dim t as UserControl1
'the next line generates the error
t.MyMethod
sleepyg
Mar 19th, 2001, 01:00 PM
You need to start a active x control project first. Then
after you save and start it you can add a standerd project to the list. Open it and in the toolbox on the right you will see the active x icon on the bottom. Click it
and paste on the from. Hope that helps
Glenn
:cool:
amitabh
Mar 20th, 2001, 07:56 PM
I am talking about having the code being in a standard module of the same project.
tumblingdown
Mar 21st, 2001, 01:43 AM
Think of the code in the standard modules as code to provide services to the aX control, not the other way around.
That said, you need to pass a reference of the control you wish to use to the code module (as a global reference, or function byref param).
Example: Global reference
'/ in standard module
Public g_oCtlRef As MyControl1
Public Sub DoSomething
'/
g_oCtlRef.MyMethod
'/
End Sub
'/ then on the control, you obviously have a method called MyMethod.
'/ And, when ever you wish to call your global function DoSomething from the control, you just set the g_oCtlRef to me, i.e.
Set g_oCtlRef = Me
You could also pass 'Me' as a param to DoSomething.
Hth.
td.
amitabh
Mar 21st, 2001, 04:29 AM
Would this even work if I needed the function is needed as a callback functionfor an api?(I am not on my computer so I cannot test it right now)
tumblingdown
Mar 21st, 2001, 05:45 AM
err, what are you asking?
If you want to use a API Callback, then your callback function MUST be in a module.
td.
amitabh
Mar 22nd, 2001, 12:42 AM
I know that I need to have the callback function in the Module. My problem is that ow do I call a method of the control I have created from the module in which I have the callback function. If I use the code given by you, it would not accept declaring it as MyControl1. If I declare it as type UserControl, then it gives a type mismatch error when passing Me as param.
tumblingdown
Mar 22nd, 2001, 02:45 AM
I presume you are making the api call from the control. In this case, all you do is set the global ref g_oCtlRef to Me, before you make the api call which sets the callback. The when the callback function calls you global proc, it has access to g_oCtlRef.
td.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.