So I have a "Reference" DB which contains many of my utility functions and classes. I, well, reference this database from my other databases to make use of the contained modules and/or classes. Since I can't instantiate a class object in this DB from the client DB directly, I have a class factory module in the reference DB with this method:
Code:
Public Function CreateClass(className As String) As Object
Dim myClass As Object
Select Case className
Case "clsChilkat"
Set myClass = New clsChilkat
Case "clsExcel"
Set myClass = New clsExcel
Case "clsFileDialog"
Set myClass = New clsFileDialog
Case "clsInfo"
Set myClass = New clsInfo
Case "clsOutlook"
Set myClass = New clsOutlook
Case "clsXml"
Set myClass = New clsXML
End Select
Set CreateClass = myClass
Set myClass = Nothing
End Function
In my client DB, I instantiate the class like this:
Code:
Dim oInfo As clsInfo
Set oInfo = CreateClass("clsInfo")
This is working perfectly so far, except it's subject to errors if I add a new class to the reference DB and forget to add a Case for it in the above code. What I'd like to do is remove the need for the Select Case block and somehow create the class object just from its string name. The client DB would still be coded as above, but is there a way to create a class instance in VBA code directly from the name of the class, similar to CallByName?
Thanks...