Solved

Difference between "Module" and "Class Module"

Posted on 2003-10-29
2
843 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
ID: 9641019
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
ID: 9641061
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.
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 …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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