Understanding Modules ?

I

Isis

I am new to Access (but not DB programming) - I gather that modules are
containers for functions and Global variables - in what circumstances do
you use more than one module ? Can you put multiple functions in one module
? I seem to ave had trouble doing that but functions in seperate modules
seem to available to the same forms etc from within my VB code.

Some pointers would be great !

Thanks
 
A

Albert D.Kallal

Isis said:
I am new to Access (but not DB programming) - I gather that modules are
containers for functions and Global variables - in what circumstances do
you use more than one module ? Can you put multiple functions in one
module
? I seem to ave had trouble doing that but functions in seperate modules
seem to available to the same forms etc from within my VB code.


You are correct in the above. You will OFTEN put more then one function, or
sub into a module. Note that the module MUST be different name then the
code, or function you place inside.

Why use more then one module?

Because your applications might have many different features and functions,
and
you want to group them together.....

here is a screen shot

http://www.members.shaw.ca/AlbertKallal/test/index2.htm

So, in the above you see a module called relink. Since most ms-access
applications are split, then you will have to eventually write some code
that re-links the tables on startup. So, I placed my re-link code in a
module. This makes it VERY easy to transfer this code to my next great
applications. And, also note the wordmerge code. This again has all my great
code for word merge.

So, as a application grows in complexity, it makes sense to group the code
by function. I could just throw everything into one HUGE module, and call it
junk, but that would not be very organized....
 
K

Klatuu

My practice is almost identicl to Albert's. For example, I have a module
named modDateFunctions. It contains all my date handling routines. I have
another named modExcelRoutines that has procedures specific to manipulating
Excel objects. You get the picture.

Now, there is one other trick you should be aware of. Forms and report have
their own modules or not. If you include no code and set the Has Module
property of the form/report, it is known as a "light" form/report. The
advantage is it will load much faster than a form/report that has a module.

The technique for processing events in a light form is to put the name of a
function that resides in a standard module in the event property text box in
design view. Now, that being said, I seldom have any pure light forms. What
I do is to minimize the code in a form. For example, I process current
record data editing, combo box lookups, and basic command button control in
the form. If there is any heavy coding required for the form, I have that in
a standard module. I name them so it is obvious they go together. For
example, I have a form that controls the month end data loading. It is
frmLoadMonth. There is a lot of data editing and manipulations, so I have
all the code in a standard module named modLoadMonth.

Just some thoughts to consider.
 
Top