473,414 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 3994
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
lpstrCustomFilter 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.dll" Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib _
"comdlg32.dll" Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long

Private Const OFN_FILEMUSTEXIST = &H1000
Private Const OFN_HIDEREADONLY = &H4
Private Const OFN_OVERWRITEPROMPT = &H2
Private Const OFN_PATHMUSTEXIST = &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
.lpstrInitialDir = szDefDir
.lpstrDefExt = szDefExt
If wMode = 1 Then
OFN.Flags = OFN_HIDEREADONLY Or OFN_PATHMUSTEXIST Or OFN_FILEMUSTEXIST
x = GetOpenFileName(OFN)
Else
OFN.Flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT Or
OFN_PATHMUSTEXIST
x = GetSaveFileName(OFN)
End If
If x <0 Then
If InStr(.lpstrFile, Chr$(0)) 0 Then
szFileName = Left$(.lpstrFile, InStr(.lpstrFile, Chr$(0)) - 1)
szFileTitle = Left$(.lpstrFileTitle, InStr(.lpstrFileTitle,
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(ByVal 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(szFileName, szFileTitle) - 1
szFileDir = Left(szFileName, intInstr)
End Sub

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

Property Let ModeOpen(DialogMode As Boolean)
wMode = DialogMode * -1
End Property
Property Let Title(DialogTitle As String)
szDialogTitle = DialogTitle
End Property
Property Let FileName(DefaultFile As String)
szFileName = DefaultFile
End Property
Property Get FileName() As String
FileName = szFileName
End Property
Property Let Filter(FilterList As String)
szFilter = NullSepString(FilterList)
End Property
Property Let StartDir(InitialDir As String)
szDefDir = InitialDir
End Property
Property Let DefaultExtension(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
"JonathanOrlev" <Jo***********@gmail.comwrote in message
news:11**********************@i15g2000cwa.googlegr oups.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
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...
2
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...
17
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...
1
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...
2
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...
5
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: ...
6
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...
10
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...
10
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.