Frank Situmorang said:
Hello,
Can anyone help me why we still need a module if all VBA can be put in the
form or reports control source... In genereal what is the difference
between
the module and all the VBA that already exsts in the forms and reports??
One large difference is that code in standard modules can be used by ALL
forms, and the reverse is not true (in other words, code in one forms
module can't generally be used by other forms (or, if you actually do
attempt this, the form will have to be loaded, and opened).
if you look at a typical application of mine, I will have *MANY* code
modules. Here is a sample list from one of my applications....
api
60, lines of code. This is where general api code to "sleep" etc goes
basFtp
1320, this my custom ftp library code to upload, and download stuff from a
web site..
BookingStuff
1592, lines of code. There is where most of my general booking processing
code goes..."many" forms will share and use this code..and by using a
module, I don't have to repeat the code over and over in each form that uses
this code..
CGZipFiles - my custom routines to zip, and un-zip windows files
clsRidesPBar - my custom code for a progress bar...again, many forms might
need progress bar.
FileOpenApi - code to pop open the windows file dialog to select a file
locks - code for my custom locking code...
I have **many** more modules in this application, but as you can see, in
MOST
cases, the above code does NOT belong in a form, and furthermore it makes
it a
snap to share the code with other applications, or even additional forms....
So, code that you place in a standard module (as opposed to forms modules)
is the type of code that really don't belong in the form, but is code that
"many" forms and parts of the application may need...