Solved

Difference between "Module" and "Class Module"

Posted on 2003-10-29
2
840 Views
Last Modified: 2011-10-03
I want to know the difference.
Does anyone know where I can find documents talking about it?
Thanks
0
Comment
Question by:meciab
2 Comments
 
LVL 8

Accepted Solution

by:
HaydnH earned 50 total points
Comment Utility
From the Access help files:

_________________________________________________________________

Creating Custom Objects with Class Modules

You can use a class module to create a definition for a custom object. The name with which you save the class module becomes the name of your custom object. Public Sub and Function procedures that you define within a class module become custom methods of the object. Public Property Let, Property Get, and Property Set procedures become properties of the object.

Once you've defined procedures within the class module, you can create the new object by creating a new instance of the class. To create a new instance of a class, you declare a variable of the type defined by that class. For example, if the name of your class is ABasicClass, you would create a new instance of it in the following manner:

Dim abc As New ABasicClass
When you run the code containing this declaration, Visual Basic creates the new instance. You can then apply its methods and properties by using the variable abc. For example, if you've defined a custom method called ListNames, you could apply it as follows:

abc.ListNames
_________________________________________________________________


For more information see the help file section "Program with Class Modules":

 - enter "class module" in the index,
 - "Create a class module that is not associated with a form or report" will appear
 - select "For information on using class modules, click <button>"

Haydn.

0
 
LVL 17

Expert Comment

by:JezWalters
Comment Utility
A Class module is roughly equivalent to a C++ class (if you're familiar with that).  Each class module effectively defines a data type, composed of the data items it is made up of and a set of procedures that operate on them.

If you define public Property Let, Get or Set procedures you can control access to the data members of your classes (for example, to only permit valid data combinations).  Any other public procedures you specify become methods you can inkvoke on each object of the class type.

Using classes allows you to "hide" complexity and protect data that is "private" to how a particular object works.  Although standard modules can also contain variables and procedures, they cannot be used to define objects.  In other words:

Dim YourObject As YourClassModule     ' Valid
Dim YourObject As YourStandardModule  ' Invalid

If you want more information, look up "class modules" in the Access on-line help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now