code organization

G

Guest

Hi,
where should I put function code so that it can be reachable from anywhere
in program.
Is there any good text about code organization in access db: modules and
stuff.
thanx

alek_mil
 
G

Graham R Seach

Alek,

If you want code to be available from anywhere in the application, it has to
be in a standard module, but it must be declared Public:
Public Sub myProcedure()
To make the code available only from within the module in which is is
declared, declare it as Private.

If you want code to be available from anywhere in the application, but only
when a form is open, you can put it in the form's class module. Even then,
it must be declared Public. To get at that code, you'll need to include the
form in the call:
Forms!frmMyForm.myProcedure
....or...
Form_frmMyForm.myProcedure
To make a form's/report's code available only within the form/report,
declare it as Private.

If you want the code to be available only from within the module or class
that instantiated (created) it, place it in a class. But the procedure (now
called a Method) must be declared Public. Assuming you have a class called
myClass, and a procedure (method) within that class called myMethod, you
would call it like so:
Dim cls As myClass
Set cls = New myClass
cls.myMethod
' - - - -
' - - - -
Set cls = Nothing

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top