473,729 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A simple question: What is the difference between a Module and a Class Module? (And Office 2003 Help system)

Hello everyone,

I have a newbe question:

In Access (2003) VBA, what is the difference between a Module and a
Class Module in the VBA development environment?

If I remember correctly, new types of objects (classes) can only be
defined in Class modules.

Am I correct?

Also, can you please tell me what is the keyword used to define a new
class?

If I have the keyword, I can probably be able to find the help in MS
Access's help program, but without it I cannot find it.

apropos the help system,
I think that Office 2003 help system is horrible, probably the worst I
ever seen. I almost cannot find anything I need, including things I
know their name. I just don't know how this help system works. For
example, this system does not recognize quotes: If I type "A B", it
considers it as A and B, and maybe A or B, I don't know.

I don't need explanations about it, but please tell me if you also it
is so horrible.

Thanks,

Jonathan Orlev

Jan 4 '07 #1
6 4030
OK, I found something in the help system.

They say there that a Class module is used to define new classes, and
If I understand correctly, the name of the module is the name of the
new class.

But how do I change the default name of the class module, which is
'ClassN' (where N is a number), to something else?

Thanks,

Jonathan
JonathanOrlev wrote:
Hello everyone,

I have a newbe question:

In Access (2003) VBA, what is the difference between a Module and a
Class Module in the VBA development environment?

If I remember correctly, new types of objects (classes) can only be
defined in Class modules.

Am I correct?

Also, can you please tell me what is the keyword used to define a new
class?

If I have the keyword, I can probably be able to find the help in MS
Access's help program, but without it I cannot find it.

apropos the help system,
I think that Office 2003 help system is horrible, probably the worst I
ever seen. I almost cannot find anything I need, including things I
know their name. I just don't know how this help system works. For
example, this system does not recognize quotes: If I type "A B", it
considers it as A and B, and maybe A or B, I don't know.

I don't need explanations about it, but please tell me if you also it
is so horrible.

Thanks,

Jonathan Orlev
Jan 4 '07 #2
Well, I now see that when saving the DB, the program as for a name for
the module. So I chose an appropriate name, although I don't know if I
can re-name it without deleting it and creating a new one, but it does
make some sense I have to say.

Thanks,

Jonathan
JonathanOrlev wrote:
OK, I found something in the help system.

They say there that a Class module is used to define new classes, and
If I understand correctly, the name of the module is the name of the
new class.

But how do I change the default name of the class module, which is
'ClassN' (where N is a number), to something else?

Thanks,

Jonathan
JonathanOrlev wrote:
Hello everyone,

I have a newbe question:

In Access (2003) VBA, what is the difference between a Module and a
Class Module in the VBA development environment?

If I remember correctly, new types of objects (classes) can only be
defined in Class modules.

Am I correct?

Also, can you please tell me what is the keyword used to define a new
class?

If I have the keyword, I can probably be able to find the help in MS
Access's help program, but without it I cannot find it.

apropos the help system,
I think that Office 2003 help system is horrible, probably the worst I
ever seen. I almost cannot find anything I need, including things I
know their name. I just don't know how this help system works. For
example, this system does not recognize quotes: If I type "A B", it
considers it as A and B, and maybe A or B, I don't know.

I don't need explanations about it, but please tell me if you also it
is so horrible.

Thanks,

Jonathan Orlev
Jan 4 '07 #3
Glad we could help. ;o)

JonathanOrlev wrote:
Well, I now see that when saving the DB, the program as for a name for
the module. So I chose an appropriate name, although I don't know if I
can re-name it without deleting it and creating a new one, but it does
make some sense I have to say.

Thanks,

Jonathan
Jan 4 '07 #4
Rightly or wrongly I think about it like this, A form is a class, or
rather derived from a class.

So when you write your own class, although it looks like it, it's not a
function, it is like a "plan" , "a map" or maybe "a list" of
instructions like in the case of the form class, the Form class
controls the building of the form.

Look at it another way ---
When you add controls to a Form, text boxes, combo boxes etc, you are
creating a class in its own right, you can actually duplicate your
form, (not copy it) in the sense that you can open another instance of
it, or even a hundred instances of it. They all will be exactly the
same as the original form you built.

Each task you perform in the database is normally accessed through a
form. In effect you are designing a class to handle a particular
function.

And that's when you can write your own class when you identify a
specific function, a repetitive function in your database, why write
separate code to do it ? Put all the code into a class module and call
the class.

Jan 4 '07 #5
ThanQ Gizmo for the information. I will have to read it again to fully
understand, but I just want to show you that I read it.

Regards,

Jonathan

Uncle Gizmo wrote:
Rightly or wrongly I think about it like this, A form is a class, or
rather derived from a class.

So when you write your own class, although it looks like it, it's not a
function, it is like a "plan" , "a map" or maybe "a list" of
instructions like in the case of the form class, the Form class
controls the building of the form.

Look at it another way ---
When you add controls to a Form, text boxes, combo boxes etc, you are
creating a class in its own right, you can actually duplicate your
form, (not copy it) in the sense that you can open another instance of
it, or even a hundred instances of it. They all will be exactly the
same as the original form you built.

Each task you perform in the database is normally accessed through a
form. In effect you are designing a class to handle a particular
function.

And that's when you can write your own class when you identify a
specific function, a repetitive function in your database, why write
separate code to do it ? Put all the code into a class module and call
the class.
Jan 7 '07 #6
To rename a class:-
1) open the VBA IDE
(Alt-F11 on the keyboard)
2) Click on the class in Project Explorer
(Ctrl-R on the keyboard if Project Explorer isn't open)
3) Double Click on the class name in the properties window
(F4 on the keyboard if Properties isn't open)

Having said that you really should decide on a class name when you first
create it and stick with that.

The difference between a Module an a Class module.

A module holds code which is global to the project. The code in a module is
frequently a number of functions which are relatively unrelated.

A class module is a code template which represents something. The code in a
class module is all related and should be encapsulated (i.e. relies only on
itself) although this is not by any stretch of the imagination always
possible.

To show the differences have a look at
http://www.mvps.org/access/api/api0001.htm which shows how to use the
Open/Save File dialog in a standard module.

Personally I prefer to use a class module for this as it matches more easily
with the common dialog control and allows me to more easily convert apps
where that control has ben used, also thinking of the Open/Save dialog as a
form or object is more intuitive to me. So the code for a class module
tohandle thiscoule look like this.

' ******* Code Start ********
Option Explicit

'Code Courtesy of
'Terry Kreft

Private Type OPENFILENAME
lStructSize As Long
hWnd As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilt er As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Private Declare Function GetOpenFileName Lib _
"comdlg32.d ll" Alias "GetOpenFileNam eA" _
(pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib _
"comdlg32.d ll" Alias "GetSaveFileNam eA" _
(pOpenfilename As OPENFILENAME) As Long

Private Const OFN_FILEMUSTEXI ST = &H1000
Private Const OFN_HIDEREADONL Y = &H4
Private Const OFN_OVERWRITEPR OMPT = &H2
Private Const OFN_PATHMUSTEXI ST = &H800
Private Const OFN_SAVE = 0
Private Const OFN_OPEN = 1

Private lngHwnd As Long
Private wMode As Integer
Private szDialogTitle As String
Private szFileName As String
Private szFilter As String
Private szDefDir As String
Private szDefExt As String
Private szFileTitle As String
Private szFileDir As String
Private intFilterIndex As Integer
Public Function Action() As String
Dim x As Long, OFN As OPENFILENAME
Call SetDefs
With OFN
.lStructSize = Len(OFN)
.hWnd = lngHwnd
.lpstrTitle = szDialogTitle
.lpstrFile = szFileName & String$(250 - Len(szFileName) , 0)
.nMaxFile = 255
.lpstrFileTitle = String$(255, 0)
.nMaxFileTitle = 255
.lpstrFilter = szFilter
.nFilterIndex = intFilterIndex
.lpstrInitialDi r = szDefDir
.lpstrDefExt = szDefExt
If wMode = 1 Then
OFN.Flags = OFN_HIDEREADONL Y Or OFN_PATHMUSTEXI ST Or OFN_FILEMUSTEXI ST
x = GetOpenFileName (OFN)
Else
OFN.Flags = OFN_HIDEREADONL Y Or OFN_OVERWRITEPR OMPT Or
OFN_PATHMUSTEXI ST
x = GetSaveFileName (OFN)
End If
If x <0 Then
If InStr(.lpstrFil e, Chr$(0)) 0 Then
szFileName = Left$(.lpstrFil e, InStr(.lpstrFil e, Chr$(0)) - 1)
szFileTitle = Left$(.lpstrFil eTitle, InStr(.lpstrFil eTitle,
Chr$(0)) - 1)
Call getFile_Dir
End If
Else
szFileName = ""
End If
End With
Action = szFileName
End Function
'Pass a bar separated string and returns a Null separated string
Private Function NullSepString(B yVal BarString As String) As String
Dim intInstr As Integer
Const vbBar = "|"
Do
intInstr = InStr(BarString , vbBar)
If intInstr 0 Then Mid(BarString, intInstr, 1) = vbNullChar
Loop While intInstr 0
NullSepString = BarString
End Function
Private Sub getFile_Dir()
Dim intInstr As Integer
intInstr = InStr(szFileNam e, szFileTitle) - 1
szFileDir = Left(szFileName , intInstr)
End Sub

Property Let hWnd(SourceHwnd As Long)
lngHwnd = SourceHwnd
End Property

Property Let ModeOpen(Dialog Mode As Boolean)
wMode = DialogMode * -1
End Property
Property Let Title(DialogTit le As String)
szDialogTitle = DialogTitle
End Property
Property Let FileName(Defaul tFile As String)
szFileName = DefaultFile
End Property
Property Get FileName() As String
FileName = szFileName
End Property
Property Let Filter(FilterLi st As String)
szFilter = NullSepString(F ilterList)
End Property
Property Let StartDir(Initia lDir As String)
szDefDir = InitialDir
End Property
Property Let DefaultExtensio n(DefExt As String)
szDefExt = DefExt
End Property
Property Get FileTitle()
FileTitle = szFileTitle
End Property
Property Get FileDir() As String
FileDir = szFileDir
End Property
Private Sub SetDefs()
If lngHwnd = 0 Then lngHwnd = 0
If szFilter = "" Then szFilter = NullSepString(" All Files|*.*")
If szDefDir = "" Then szDefDir = "C:\"
If intFilterIndex = 0 Then intFilterIndex = 1
End Sub
' ******* Code End ********

If we called this class cDialog then the code to use it could be as follows

' ******* Code Start ********
Dim cD As cDialog
Dim strFileName As String

Set cD = New cDialog

With cD
.Filter = "Excel Files|*.xls|All Files|*.*"
.StartDir = "c:\"
.Title = "Find Excel File ..."
.ModeOpen = True
strFileName = .Action
End With
Set cD = Nothing

Debug.Print strFileName

' ******* Code End ********
--

Terry Kreft
"JonathanOr lev" <Jo***********@ gmail.comwrote in message
news:11******** **************@ i15g2000cwa.goo glegroups.com.. .
Hello everyone,

I have a newbe question:

In Access (2003) VBA, what is the difference between a Module and a
Class Module in the VBA development environment?

If I remember correctly, new types of objects (classes) can only be
defined in Class modules.

Am I correct?

Also, can you please tell me what is the keyword used to define a new
class?

If I have the keyword, I can probably be able to find the help in MS
Access's help program, but without it I cannot find it.

apropos the help system,
I think that Office 2003 help system is horrible, probably the worst I
ever seen. I almost cannot find anything I need, including things I
know their name. I just don't know how this help system works. For
example, this system does not recognize quotes: If I type "A B", it
considers it as A and B, and maybe A or B, I don't know.

I don't need explanations about it, but please tell me if you also it
is so horrible.

Thanks,

Jonathan Orlev

Jan 8 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1344
by: Terrance | last post by:
Hello, everyone. I was hoping if someone could help me out with a problem that I'm trying to solve? I have a project that I'm working on. As the splashscreen launches for an application I check the directory for the location of a file and I assign that directory path to a class member in my main module; so, I have the following syntax cClass.mydirectory = (path of file). However, when I Load a form I have to recreate the class object cClass...
2
5361
by: MENTAT | last post by:
Hi, I am trying to create an installer for my web application. So I added a web setup project to my solution (I am using VS.NET 2003). Been playing around with it since then and it basically works. Now, I am wondering if there is any way to change the directory that the installer installs the files to. I want to be able to put my files in a specified directory (user specified is good, but i don't mind hardcoding the path either) and...
17
26547
by: Pam Ammond | last post by:
I need to use Microsoft Access Automation within a Visual Studio 2003 program written in C# for Windows Forms. When a button is clicked in my VS.NET program, I want it to run a Microsoft Access Module. Here is the info on the Microsoft Access Module: Microsoft Access 2003 mdb is located at: C:\C#.NET\Esperanza The mdb is called: EspThr.mdb The Module is called: Module1 The function is: Public Function WriteHTML() As Integer The result...
1
1625
by: AmiciDan | last post by:
When I attempt to create a new project in Visual Studio .NET 2003, I do NOT have the option to create the following: Microsoft Office 2003 Projects What do I need to install or do to get this option as a project type? I have a Universal MSDN subscription and am using Visual Studio .NET 2003 Enterprise Edition. I attempted to re-run the setup, but I did not see "Microsoft Office 2003 Projects" as an option.
2
8401
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
5
1253
by: Greg Smith | last post by:
I am sure this is very simple but I can't seem to get the syntax correct. I have a class that I added to my application and I would like to reference controls on a webform. Something like: WebForm1.TextBox.Text = "Fred"; Any help is greatly appreciated.
6
1294
by: TD | last post by:
OK, I didn't know where to start to ask for help with this question, but here goes. I have a Windows 2000 Pro computer with a single partition on the hard drive. I want to installed the following software on it: Microsoft Office 2000 Professional (for Access work) Microsoft Office 2003 Professional (for Access work) Microsoft Visual Basic version 6 Microsoft Visual Studio 2003 Professional ( for .Net work) Will these programs...
10
2256
by: sp | last post by:
I create an xml file in a text editor: <?xml version="1.0" encoding="utf-8"?> <elts> <elt id="1" class="c1">content1</elt> <elt id="2" class="c1">content2</elt> </elts> Then I load the file via xmlHttpRequest into xmlData variable. Why does xmlData.getElementById('1') return null and xmlData.firstChild.childNodes.className returns null also?
10
5492
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in advance
0
8921
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8763
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9202
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9148
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8151
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.