Public/Private Functions Or Subs

Treason

#@$%#!
Local time
Today, 16:56
Joined
Mar 12, 2002
Messages
340
I never really learned the differences between Public/Private, Function/Subs... instead I found what works and went with it. I have 12-15 modules in my DB, basically grouped by catagory. For example modPrintJobs, might have 12 public functions all related to printing. I might have 10 Public functions per modules. How can this arrangement affect my database and how could I fix this?
 
I'll try to keep it simple...

Subroutine

A subroutine is a process. You call it and it does something. It does not return a value.

Function

A function is a process that returns a value (or should, at least).

Public

Declaring something as Public means that it is visible throughout the project and can be used by subs or functions in other modules.

Private

This means that the sub or function can only be used within the module it is declared within.


A Sub or Function without a Private or Public declaration defaults to Public.

You can't call Public functions declared within Class Modules (being those attached to forms, reports, or standalone) without first making an instance of the class.
 
Last edited:
Ok that makes sense.

The question is... If I call a public function, contained in a module with 20 other public functions, does access load all 20 functions into memory or just the one I am calling?

Is my previously explained setup OK or would scope modifications/module splitting drastically improve my DB speeds?
 
All 20 functions would be loaded into memory. It's best to group related functions together in separate modules.
 
One addition:

If you use macros, god help you, you cannot call a sub. You can only call a function.
 

Users who are viewing this thread

Back
Top Bottom