Q re making a code library

  • Thread starter Thread starter jfp
  • Start date Start date
J

jfp

Access 2002:

I have a database containing:
a) stuff that is application specific
b) stuff that is generic in nature and needs to be put into a "code
library" so that it can be used from this as well as other (future)
apps.

After first getting it all working in one database, this is what i did:
1) make a new database (call it "library")
2) import into "library" various modules from the original database
3) delete same from original database
4) in the original database, establish a reference to the library (as a
.mdb file)

This is what seems to be happening ( i have not tested this very
thoroughly yet)

1) If the only things removed from the original and put into the
library are code modules containing public subs/functions, things are
ok.
2) If definitions of UDTs ("public Type ...") are moved, compile errors
occur (undefined ...)
3) If forms are moved, code compiles but they cannot be found
(DoCmd.OpenForm) during execution

-=-=-=
Any ideas ??
 
Can't confirm the UDT problem. I use UDT and Enums in just the way you seem
to want to. I don't recall a problem. (just now checked out examples of use
of both Type and Enum on my libs and they're fine). Take care that the
modules containing the Public Type defs are not qualified with:
Option Private Module
If that were the case, then the 'Public' definition is only visible within
the library.

For the library-based form or report, my usual method is - as you have
virtually pointed out yourself - to provide a "wrapper" function.

So, if for example User log-on is handled within library code, the library
could contain Functions "Log-on User", "Browse_User" which contained the
OpenForm command to the log-on form(s) and / or the User Permissions form
etc. Similarly for library-based reports.

You do need to be careful about the recordset definitions within these
library forms and reports. The tables that they manipulate are now almost
certainly not 'local' to the library. Consequently, you will need to include
the "IN <dbname>" clause in the SQL statements used in RecordSource,
RowSource....

One or two other little things like that, but in general no great hassle to
shift stuff into a library. And no more of a problem to convert it to mde,
as well - given the usual mde caveats regarding create form/control/report
etc.

Good luck
CD
 
Thanks for the detailed reply !
My original post may have been a bit in error --
I am still working on this -- moving stuff piece by piece from
application into library. So far ...
1) various Subs and Functions seem fine
2) when i move the code module containing definition of a UDT into the
library, compiler has no problems
3) when i move the class module containing definition of a class into
the library, compiler gives me an error "User defined type not defined"
when i declare an instance of the class. (I guess it was this wording
that led to my original complaint about UDTs.)

So -- if:
my library is "EEE_AccessLib.mdb"
the library has a class module "EEE_PrintReport_Class"
the application wants to declare an instance of that class,
how do i do it ?
Originally, when everything was in one place, this worked:
Private PR As EEE_PrintReport_Class
This is the line that now gives me the "... not defined" error.
I tried changing it to:
Private PR As EEE_AccessLib.EEE_PrintReport_Class
but that did not help.

Note: after i typed this:
Private PR As EEE_AccessLib.
IntelliSense popped up a list of public UDTs etc in the library -- but
not the class.

Any ideas ?
-=-=-=
 
If i export the code from the class module, i see at the top a bunch of
lines that do NOT show in the VB editor window. Included in these is:
Attribute VB_Exposed = False
Could this be the problem? (Sounds sort of like the "Option Private
Module" you warned me about)
I tried putting this line into the code
Attribute VB_Exposed = True
but got a compiler error.
-=-=-=
 
If you make the VB_Exposed = True change in a text editor, external to the
IDE, and then import the source, you should get better results.
Have a look (Google Groups mpa.modulesdaovba) at the thread "Calling a Class
Module Method" Oct/Nov 2000 for more detail.

CD
 
Amazing - absolutely amazing.
Is this REALLY the only way to do this ?
I have to export the code, change one of the hidden lines, and then
import it ? (I also had to change the "Creatable" attribute so i could
instantiate the class -- but, at least, it now compiles)
Is there any way to do this from the VBA IDE ??

I will check out the google group -- but -- i just had to vent some
steam at this apparent stupidity ...
 
Back
Top