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

How do I Instantiate / use an OCX control in VB

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
Client has an OCX with no source code (they lost the code 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. They call it to add a resource or a task, etc.

If I add the OCX file to the References collection in VB, 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!


 
DOes this not work?

Dim myObj as New DLLName.className

myObj.property = blahblah
 
It will NOT work with the New keyword. However, I was able to get it to work with CreateObject. After I added a reference to the OCX file using the browse feature the following code works:

Dim myObj As Object
Set myObj = CreateObject("OCXFileName.UserFormName")
myObj.AnyPublicUserFormNameMethod
Set myObj = Nothing

Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top