Class Module Instancing

  • Thread starter Thread starter Damien
  • Start date Start date
D

Damien

Can anyone tell me what the Instancing options for a Class
module mean ?
1 - Private
2 - PublicNotCreatable

Thanks
 
Private means that no other VBA project will be able to see the class. For
example, if you build a class in a library database and then from another
database, create a reference to this library you won't be able to see or use
the class from the new database. Code in the library database can still see
and use it so your calling code may indirectly be using the class but you
won't be able to declare a variable with it or refer to one of its
instances.

PublicNotCreatable means that an external project can see and use the
class - it just can't create a new instance of it. This is a bit of a
nuisance but is easily solved by creating a helper function in the library
database in a standard module in the library db that returns a new instance
of your class. For a class named foo:

Public Function Newfoo() as Foo
NewFoo=new Foo
end function

Often, I will also build in the parameters to set up the new instance
of the class and do it all from the helper function.
 
Thanks Sandra, there didn't seem to be anything in the
Help files on that.

Damien
-----Original Message-----
Private means that no other VBA project will be able to see the class. For
example, if you build a class in a library database and then from another
database, create a reference to this library you won't be able to see or use
the class from the new database. Code in the library database can still see
and use it so your calling code may indirectly be using the class but you
won't be able to declare a variable with it or refer to one of its
instances.

PublicNotCreatable means that an external project can see and use the
class - it just can't create a new instance of it. This is a bit of a
nuisance but is easily solved by creating a helper function in the library
database in a standard module in the library db that returns a new instance
of your class. For a class named foo:

Public Function Newfoo() as Foo
NewFoo=new Foo
end function

Often, I will also build in the parameters to set up the new instance
of the class and do it all from the helper function.

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.
Can anyone tell me what the Instancing options for a Class
module mean ?
1 - Private
2 - PublicNotCreatable

Thanks

.
 
Back
Top