Solved

Module Types

Posted on 2011-02-17
18
812 Views
Last Modified: 2013-11-28
Class Modules are used to create and define custom objects.
Form/ report modules contain the code behind forms/ reports.
But what are the modules that contain my subroutines and functions called?
0
Comment
Question by:Milewskp
18 Comments
 
LVL 17

Accepted Solution

by:
Barry Cunney earned 250 total points
ID: 34920414
I think they are called Standard Modules
http://www.tek-tips.com/faqs.cfm?fid=5319
0
 
LVL 28

Expert Comment

by:omgang
ID: 34920426
Standard module
OM Gang
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 34920513
"Form/ report modules contain the code behind forms/ reports."
In fact, Form and Report *are* Class Modules also, except they are contained within the Form and Report object.

""But what are the modules that contain my subroutines and functions called?"
Standard VBA Modules.

mx
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 75
ID: 34920525
typo:

"In fact, Form and Report *are* Class Modules also"

>> In fact, Form and Report modules *are* Class Modules also.

mx
0
 
LVL 1

Author Comment

by:Milewskp
ID: 34920669
Hi mx,
<Form and Report modules *are* Class Modules >
Doesn't this imply that Forms and Reports are Classes?
The way I read BCUNNEY's link, Forms, Reports and Classes are all objects, but a form is not a report is not a class - they are distinct.
0
 
LVL 75
ID: 34920781
"Doesn't this imply that Forms and Reports are Classes?"
No. Forms & Reports are Objects.

The code modules contained within are Class Modules.  100% Guaranteed.

Have you ever noticed that you can create custom Form/Report properties *just* like you can in external Class Modules?  I do it all the time.  The only difference between the two is that external Class modules have Initialize and Terminate events.  Form and Reports ... Open/OnLoad ... Unload/Close.

That's how it is.

mx
0
 
LVL 75
ID: 34920999
You can see right in the VBA Object Browser (see image 1).

When you do this in code:

Dim frm As Form
Set frm = Form_frmMain
You have just set an object variable (frm) to Form Main's Class module

Note the custom Properties in image 2/3 for one of my Forms ...

mx
Capture1.gif
Capture2.gif
Capture3.gif
0
 
LVL 1

Author Comment

by:Milewskp
ID: 34922397
Hi mx,
<Form and Report modules *are* Class Modules >
If Form and Report Modules are Class Modules, then when you say 'Class module', you could be taking about a Form Module, a Report Module or a Class module that is not associated with a form or report.
So, when you are talking about this third type of module with your friends, what do you call it to distinguish it from Report Modules and Form Modules ('Class module that is not associated with a form or report' is as cumbersome as 'The artist formerly known as Prince'.)
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 34922458
"So, when you are talking about this third type of module with your friends"
What 3rd type ?

In reality, there are only two types:
Regular VBA Modules
Class Modules
However, it's 'convenient' ... when code in a Form or Report is being discussed ... to say the Form module or Report Module. But that does not change the fact those modules are Class modules.

Remember ... A Form /  Report can have No module ... by setting the Has Module property to No.
When the property is set to Yes ... then what you have is a Class module 'behind' the Form/Report object.

mx
0
 
LVL 1

Author Comment

by:Milewskp
ID: 34922959
Hi mx,
<<"Doesn't this imply that Forms and Reports are Classes?">  No. Forms & Reports are Objects.>>
If you don't think that Forms and Reports are classes, I don't understand why you would want to call their modules 'Class Modules'. But of course, what you call them is your business.

Regardless, what you call a 'Class Module', BCUNNEY's link (http://www.tek-tips.com/faqs.cfm?fid=5319 )  calls an 'Object Module'. To confuse matters further, the VBA Project Explorer window lists Form and Report modules as 'Class Objects', and 'external' class modules as 'Class Modules'.

I prefer the term Object Module, since these modules describe objects, and because I can then use two words ('Class Module') instead of three (External Class Module) to describe what Microsoft calls 'Class Module'. But unless one term is much more commonly used than the other, I'd say it boils down to personal preference.

However, even if you accept the latter definition of Class module, it is not a very helpful definition, because whenever you use it you could be talking about a Form Class Module, a Report Class Module or an External Class Module.
From what I've googled, a Class is a custom object (or a template used to create custom objects), and a VBA code module that defines the properties, methods and events of a Class is called a Class Module.

Since a form is also a custom object and the VBA code module behind a form defines at least  some of its properties, methods and events, I agree that it is a Class Module.




A form, and the VBA code module that contains the code behind it, seems to me to have nothing to do with a Class. So it seems illogical to me to use the adjective 'Class' to describe such a module. On teh other hand, since it is the module behind a form, the obviuos name for such a module would be Form Module.
0
 
LVL 75
ID: 34923014
"A form, and the VBA code module that contains the code behind it, seems to me to have nothing to do with a Class."
It Does!  A Form or Report Module is a Class Module. Period. That's how it is.
mx
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 34923083
From Help:

Type property as it applies to the Module object.

Indicates whether a module is a standard module or a class module. Read-only AcModuleType.

AcModuleType can be one of these AcModuleType constants.
acClassModule            1
acStandardModule      0

Then run this code inside of a Form or Report:

Private Sub Form_Load()

    Dim x, y, z
     x = acClassModule
     y = acStandardModule
     z = Me.Module.Type
     Debug.Print x & " " & y & " "; z
   
End Sub

This is the result:

1 0  1  (x,y,z)

They Type = 1 (one) = Class

As I said, the are only two types of Modules:
Standard VBA
Class

Any questions?

mx

0
 
LVL 75
ID: 34923102
In fact, do

Debug.Print Me.Module.Type

inside of a external Class module and you will get 1 (one).

Note that Me works in a Class module and *only* a Class module, which is why it works in a Form or Report (class) module.

mx
0
 
LVL 1

Author Comment

by:Milewskp
ID: 34925664
Hi all,
If my last post sounds like incoherent rambling, its because the last half was a draft that should have been deleted. The post should have been this:

<Hi mx,
<<"Doesn't this imply that Forms and Reports are Classes?">  No. Forms & Reports are Objects.>>
If you don't think that Forms and Reports are classes, I don't understand why you would want to call their modules 'Class Modules'. But of course, what you call them is your business.

Regardless, what you call a 'Class Module', BCUNNEY's link (http://www.tek-tips.com/faqs.cfm?fid=5319 )  calls an 'Object Module'. To confuse matters further, the VBA Project Explorer window lists Form and Report modules as 'Class Objects', and 'external' class modules as 'Class Modules'.

I prefer the term Object Module, since these modules describe objects, and because I can then use two words ('Class Module') instead of three (External Class Module) to describe what Microsoft calls 'Class Module'. But unless one term is much more commonly used than the other, I'd say it boils down to personal preference.>

0
 
LVL 1

Author Comment

by:Milewskp
ID: 34925669
Hi mx,
Thanks for that.
0
 
LVL 75
ID: 34927894
Milewskp:
With all due respect ... and this is not about points, this question has been answered.  If you want to disagree with Microsoft Help on the subject, that's fine. But ... it does not change the facts, nor does some random blog on the net by some totally unknown author ... who has a certain take on the subject.

That article does *not* change that fact - no matter how is is spun - that Form and Report modules are Class modules. Period.  The code snippet I posted proves this beyond any reasonable doubt.  There are only two kinds of modules. Period.  Just how and where the keyword Me is used ... alone demonstrates this.

There is no problem using the term Form and/or Report Module ... as long as you understand the Form and Report modules are Class modules.  There is no 3rd type.

mx

0
 
LVL 1

Author Comment

by:Milewskp
ID: 34952103
All,
Thanks for your help.

mx,
Thanks also for your patience. I think I get it now.


I will split the points.
0
 
LVL 75
ID: 34953545
No problem.

thx.mx
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question