How to add reference to certain Type Libraries programmatically in VB6 ?

I have a VB application which needs to be checked for available type libraries on application startup and set reference to appropriate type library.

Please explain with a code how to get/add/remove reference to certain Type Libraries programmatically in VB6 ?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


You can't programaticaly add or remove a reference to a library, you can't change a reference after compiling as it's used during the compile process.

What you're looking for is Late Binding. One major drawback is no intellisense but it works :)
Dm oObject As Object
Set oObject = CreateObject("My.Project")

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pramodkumarAuthor Commented:
hi c0ldfyr3 !

Thanks for the comment :) !!
I got your idea of using late binding.

To be more clear about my scenario, my exe will depend on 2 tlbs while developing,
but after installation at the client PC,  i will be checking for any newer version of the tlbs.
If new version is found then the new available 2 tlbs at his system has to be referenced and if NOT then the available 2 tlbs at this system need to be referenced.

So, how can I make my exe to "refer" based on the result of the condition ?

Also, the objects are passed as parameters in various functions. Will it still work ?

Since I have to continue working on the same project later even after the release, it will be difficult for me to code without Intellisense.
Late binding is the only option ??
I'm afraid so, references are built into a project at compile time unfortunately =( What you can do, and what I've done in the past, is have two identical project files. One with references and one without. And you use the with-ref project file to develop and the without ref project file to build, then you swap around the declarations to be as object instead of as "ClassName" before building. It's messy as hell but it works!
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

pramodkumarAuthor Commented:
ok  c0ldfyr3 ..

You kept your comment very neat and simple. Cause, even I too thought in your way of finishing all the coding jobs first with the references set and then create a copy, take off the references and do a quick "Find and Replace" thing with only the objects.

You caught my thought too ! :) ok.. i'm happy. I feel you are almost there, really close to win my 500 points.

Within 2-4 days I am going implement "late binding" and test it as like your comments. If it works perfect then you surely bag a huge 500 points for the same !! Or else i may need more help from you ;)

Kindly wait till I finish my testing and get back here.

Thanks a lot !! :)

Cool let me know if there's anything else I can do!
pramodkumarAuthor Commented:
Hi c0ldfyr3 !

Kindly give me some more time as I am little busy with some other modules of the application.
Will let you once I check late binding for the application.

thank you :)
pramodkumarAuthor Commented:
Hi c0ldfyr3 !
Very sry for making you to wait (if you are). The testing with late binding is yet to start since we loose the "intellisense" if we go for it right now. I am currently working with other modules..

Should I accept your answer for the moment for your courtesy shown in response to my question ? Moreover, I am having strong confidence in your answer that it will work, but cannot assure at the moment that it worked since I have to complete other modules..

Thank you :)
It doesn't bother me at all take your time - the points don't really make that much of a difference we do it to help ;)

I get emails when you reply so whenever you do get the time to revisit it just post a reply and I'll see what I can do to further assist you =)
pramodkumarAuthor Commented:
Many thanks c0ldfyr3 !!
It worked though the crude way !!
pramodkumarAuthor Commented:
perfect answer !
I created a DLL library in Visual basic express edition 2008.  I followed the process of creating a reference on this the dll file.  This part is OK.

Now, I want to remove the reference  from my projoct and want include the class project (of this DLL) in the project group in order to debug the coding. What is the procedure for it.

I do appreciate your help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.