Solved

Difference between "Module" and "Class Module"

Posted on 2003-10-29
2
847 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 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