Solved

Difference between "Module" and "Class Module"

Posted on 2003-10-29
2
845 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

710 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