public vs private

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am not a programmer but I have had to learn to wrote simple code to
calculate an amount due based upon entries in several fields. It works but
now I'm concerned about the need for the same code to work in all queries and
reports that utilize those fields and the resulting calculation. Can someone
help me understand -- the public/private code issue. And, I don't understand
how to make it public if that's what I need to do. Any help you can offer
will be appreciated.
 
Firstly, there are 2 kinds of code modules in Access:
a) those that show up on the Modules tab of the Database window;
b) those that are part of a form/report.

You need the code in (a) if you plan to use it across different
forms/reports/queries.

When the code is in a standard module like that, it is public by default.
You can add Public to the declaration for clarity, but it makes no
difference. If you add Private to the declaration, the procedure will only
be available to other routines in that module.
 
hi Nancy,
I am not a programmer but I have had to learn to wrote simple code to
calculate an amount due based upon entries in several fields. It works but
now I'm concerned about the need for the same code to work in all queries and
reports that utilize those fields and the resulting calculation. Can someone
help me understand -- the public/private code issue.
First of all, there are two types of modules:

- class modules, which carry the code behind a form or a report
- standard modul, which is only a collection of code

You need to put your function in a standard module and declare it as
public (e.g. Public Function CalcIt() As Currency).

Private code can only be called form the module in which it is declared.
Public functions can be called from everywhere.


mfG
--> stefan <--
 
Thanks to both of you. I'm assuming that you mean that I can open a module,
put my code there and then it will apply across the database. i.e., that
will make it "public." Is that correct?
 
Yes. In a standard module, each procedure is publicly available, unless you
explicitly mark it as Private.
 
Allen said:
Firstly, there are 2 kinds of code modules in Access:
a) those that show up on the Modules tab of the Database window;
b) those that are part of a form/report

Stefan said:
First of all, there are two types of modules:
- class modules, which carry the code behind a form or a report
- standard modul, which is only a collection of code

[OT]:
Firstly and first of all, there are two kinds of posters in Access
newsgroups:
- a) those who think there are 2 types of code modules;
- b) those who think it's not that simple ;-)

Jamie.

--
 
hi Jamie,
Firstly and first of all, there are two kinds of posters in Access
newsgroups:
- a) those who think there are 2 types of code modules;
- b) those who think it's not that simple ;-)
<g> but it is a good pragmatical approach.


mfG
--> stefan <--
 
hi Jamie,

onedaywhenwrote:

<g> but it is a good pragmatical approach.

<g> also but I could justify a classification of three i.e.

1) Microsoft Access Class Objects
2) Modules
3) Class Modules

Jamie.

--
 
hi Jamie,
<g> also but I could justify a classification of three i.e.
1) Microsoft Access Class Objects
2) Modules
3) Class Modules
Don't think so. They are all just class modules.

1) Code behind form modules are just two part classes/objects as you
have in .Net.

2) Same thing as 1). As you can declare properties in it, they are
classes. The look like a lazy singelton implentation to me.

3) "Real" classes.

You just have not full access on the class source in 1) and 2).

mfG
--> stefan <--
 
hi Jamie,



Don't think so. They are all just class modules.

Then why are then on different levels in the VBE project explorer
treeview? It's not my classification <g>!

Jamie.

--
 
hi Jamie,
Then why are then on different levels in the VBE project explorer
treeview? It's not my classification <g>!
To make understanding easier for the beginner. To give a better
presentation of it.

But this is some kind of speculation. Only some of the Access team
members can enlighten us here :)


mfG
--> stefan <--
 
hi Jamie,
I can declare properties in Standard Module (.bas) so does that make
it a class also <g>?
ms-help://MS.MSDN.vAug06.en/dv_vbalr/html/3155edaf-8ebd-45c6-9cef-11d5d2dc8d38.htm
--
You can use Property only at module level. This means the declaration
context for a property must be a class, structure, module, or interface,
and cannot be a source file, namespace, procedure, or block.
--

It is possible to have a property with out a class, but this is
comparing apples and oranges, as it concerns only the newer .Net languages.

So, it may be a class or not. I have no facts for either my assertion or
against it.
From my point of view it is one. A standard module looks for me like a
static class in C#/VB.NET.


mfG
--> stefan <--
 
Back
Top