Results 1 to 4 of 4
  1. #1
    Join Date
    May 2004
    Posts
    2

    Question Unanswered: Instantiate a class by name.

    Hello everybody.

    Is there a way in Microsoft Access to instantiate a class (defined through a class module) if you have it's name as a string variable?

    Imagine I have this:

    strClassName="cls_MyClass"

    and want to create an instance of class cls_MyClass. Can't use Dim here, naturally, and it looks like eval() can't help me either. Is there a way out at all?

    Thanks for your help.

  2. #2
    Join Date
    Feb 2004
    Posts
    137
    Actually, if in your mdb you have a class module named cls_MyClass, you would create an instance of it with a Dim statement thus:
    Code:
    Dim myObject As New cls_MyClass

  3. #3
    Join Date
    May 2004
    Posts
    2
    I wish!

    If that would be so, I wouldn't be asking, of course.

    Once again: the name of the class to instantiate is specified as a _string variable_. I do not know it in advance, and thus cannot write the Dim statement.

  4. #4
    Join Date
    Feb 2004
    Posts
    137
    In that case, no, it is not possible in Access. You must have the actual class name; you cannot use the New specification to create a new instance of a class with a string variable for the name.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •