How to use an ActiveX in VB6

There are two ways to reference an ActiveX in Visual Basic 6.0.  The first is to select “Project–>References” from the VB6 menu.  The second way is to select “Project–>Components…” from the VB6 menu.

Important:  You should do one or the other, but not both.

Which do you choose?   Use “Project–>References” if you are going to instantiate the ActiveX dynamically.  In other words, you’ll be creating the object dynamically using the New statement.  Such as:

Dim mailman As New ChilkatMailMan2

Dim mm as ChilkatMailMan2
Set mm = New ChilkatMailMan2

Use “Project–>Components…” if you are going to drop an instance of the component onto a Form. When you include an ActiveX using “Project–>Components…”, you’ll see icons added to your toolbox. In this case, you’ll see an icon for the Chilkat MailMan object. You would drag this onto your Form. Adding an ActiveX in this way only makes sense if the component has a visual interface. The Chilkat ActiveX components are non-visual, so there is no point in doing it this way, and I would highly recommend adding a Reference and instantiating the object instances dynamically using the New statement.

Common Errors:

If you add the ActiveX via “Project–>Components…”  and then try to instantiate an object dynamically using the New statement, you’ll get the “Invalid use of New keyword” error.

If you don’t add the ActiveX to your project in any way, (i.e not through “Project–>References” nor through “Project–>Components…”,  you’ll get the “User-defined type not defined” error.