Solved

Creating class in MS Access/VBA-Examples?

Posted on 2006-11-22
7
3,484 Views
Last Modified: 2011-08-18
Hi everybody!
I have not a big expiriance in access programming and interesting about Object oriented programming with VBA. Has any examples about classes in Access/VBA which I can using in my Access program?
Thanks in advanced.
0
Comment
Question by:zadams
[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
7 Comments
 
LVL 15

Expert Comment

by:Simon Ball
ID: 18001617
intersting.

the closest i get to proper OOp is using a module with public functions in which act as methods...

I'd be interested to see what other experts c0mment on this as i am currently learning JAVA OOp as part of my MSc.  I know you can use VB6 or .NET to write classes so I assume the sameis possible in VBA in access/excel, but I am not sure where that would be useful in Access.

You can declare an object, and set it equal to something to instansiate an object in accesss, so you can probably write you own objects too.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 18001965
How familiar are u with OO ?

Each class has a constructor/destructor, Access has its equivalent
each class u create has the following functions

Private Sub Class_Initialize()

End Sub

Private Sub Class_Terminate()

End Sub


when u instanstiate a class
eg
dim x as new clsMylass

the initialize method is called


Your class may have members, in which case u need to create the accessor functions i..e your get/set functions
in access its Public Property Let and Get

eg

set a member

Public Property Let MyField(sVal as String)
    MyField = sVal
End Property


then u can define public functions and procedures  which become methods of your class


thats it
0
 

Author Comment

by:zadams
ID: 18002061
rockiroads,
could You send any example. For example, I have Subscribers Database in a little telecom company. What class may be usefull in my case?
Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Expert Comment

by:rockiroads
ID: 18002140
simple example

here is a class. saved as clsTest



Dim sName As String

Private Sub Class_Initialize()
    sName = "not set"
End Sub

Public Property Let Name(ByVal sNewName As String)
    sName = sNewName
End Property

Public Property Get Name() As String
    Name = sName
End Property





This is how u use it

    Dim x As New clsTest
   
    Debug.Print "Initial Value", x.Name
   
    Debug.Print "Set it to fred"
    x.Name = "fred"
   
    Debug.Print "Value is now", x.Name

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 50 total points
ID: 18002153
I dont know your DB, classes are used to identify an entity, then all methods/properties of that entity are defined in that class.

Personally Access has implemented classes but there is no real OO approach here. What u can do in classes, u can do in modules as well, simply by defining them either as public or private
0
 
LVL 85
ID: 18002197
IMO, a great book one this subject is Visual Basic 6 Business Objects by Rockford Lothka. He goes into great detail about classes and how to build them, and while the book is specific to VB6 virtually all concepts are viable in Access as well.

Rocki is correct in that Access doesn't hold with the "true" definition of OO, but it's close enough to be useful on many levels. I don't necessarily agree with using modules in place of classes ... you cannot, for example, instantiate an instance of a module, but you can with a class, so if you have a Customer class, you could have a dozen or more different instances of various Customers ... you couldn't do that with a Module.
0
 

Author Comment

by:zadams
ID: 18002211
Understood.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

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