
Using class modules in a code library
It seems to me that the helper function method would be messy since you'd be
creating an object in both the library code and the callling application
without a good way to destroy the object that the library instantiated.
Fortunately, I got the answer I like better from Steve Arbaugh. For anyone
else who wants to do this, here's how. I'm working in Access 2000 but I
believe this answer would apply to 97 and 2002 as well.
The way to make this happen is to create a plain text file with these two
lines.
VB_Creatable = True
VB_Exposed = True
In the VBE:
1) Insert a new class module
2) From the Insert menu choose File and insert the text file
3) Add the class module code
Now the class module can be instantiated directly from the calling
application without any helper functions.
It seems as though you have to repeat this process each time. For example, I
tried to save a "starter" class module that would have these attributes set
this way. My idea was that I would do a "Save As" from the Access window so
I wouldn't have to keep inserting the text file. However, that didn't work
for me.
Steve's website got me started in the right direction. It's at
http://ourworld.compuserve.com/homepages/attac-cg/ if anyone else would like
to see his comments.
Best wishes for the holidays!
Quote:
> This is a limitation of VBA - you can not create a PublicCreatable
> class. No problem - just create a "helper" function in a standard
> module in the library db that returns a new instance of your class.
> For a class named Dog.
> Public Function NewDog() as Dog
> NewDog=new dog
> 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
> > I am attempting to move a class module from the application database
> file
> > into a code library (mda) file. At first I couldn't see the class
> module
> > from the application file but I solved that one with some help from
> Steve
> > Arbaugh's site at
> http://ourworld.compuserve.com/homepages/attac-cg/.
> > However, I still can't use the class in the application file. When I
> try to
> > instantiate the class, I get an "Invalid use of New Keyword" error.
> Any
> > suggestions from anyone?
> > Joel Reinford