Solved

Creating class in MS Access/VBA-Examples?

Posted on 2006-11-22
7
3,472 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 84
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

Industry Leaders: 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!

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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.

752 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