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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instantiating/using an OCX control in VBA 1

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Client has an OCX with no source code (they lost it somewhere along the line before my time). They are using it to interface into MS Project from a form (written in Uniface) which allows external OCX calls but no external DLL calls.

If I add the OCX file to the References collection in VBA, I can see the properties, methods and Declare statements using the object browser.

How do I instantiate or link to an object? It will let me Dim it but I get an error when I try to use the NEW keyword.

Also, how do I reference its methods? If I put the object on a form I cannot then see the methods which are displayed in the browser.

Thanks in advance for any help and or suggestions you can give me! Have a great day!

 
Just treat it as an object.

Dim YourOCX as Object

Now, even though Access will not display the methods and properties of YourOCX object when you type it, Access will act upon them.
 
Thanks FP! I don't know why I never think to use the generic Object. It will actually work with the following, it is just that you cannot use New with an OCX, you must use CreateObject. Once I added a reference to the OCX file using the browse feature, it worked.

Dim myObj As OCXFileName.OCXUserFormName

Set myObj = CreateObject("OCXFileName.OCXUserFormName")
SomeVar = myObj.OCXUserFormPublicFunction(ArgListIfAny)
Call myObj.OCXUserFormPublicSub(ArgListIfAny)

Thanks again for the nudge. That allowed me to put the pieces together correctly.

Have a great weekend!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top