Mapping Object Oriented Programming concepts to VBA

I'm maintaining a MS Access 2000 application. I'm accustomed to languages (e.g. Python) that provide thorough Object Oriented Programming support, and I struggle with the very limited Object Oriented Programming support in VBA. I'm wondering whether you have any suggestions regarding mapping Object Oriented Programming concepts to VBA. It seems to me that there is so much that I just can't do, and a little that I can do that requries writing much more code than I'd use in Python.

It amazes me that MS has provided such a limited oop model!
LVL 17
ramromconsultant Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VBA supports some OO concepts, and not others.

with VBA you can create your own classes, and you can create objects from those classes.  However, VBA does NOT support Inheritance, and does not truly support 'polymorphism' in the classical meaning of the term as used in OO languages such as C++, or .NET.

VBA classes do support encapsulation, and abstraction.

VBA was never designed, nor intended to be a OO language.  If you try to force pure OO concepts onto VBA, you will fail in the same way the cowboys attempting to use Ostriches to herd cows will fail.  Yes, you can strap a saddle on the back of an ostrich, and yes, you can put a set of reins on an ostrich - but that does not make the poor ostrich any type of cow-pony.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
That was a bill-full!
oh, and by the way, just because you can't make an ostrich into a cow-pony, does not make the ostrich any less valuable as a bird, and kids still love to see them at the zoo.  Access and VBA have their place in the IT marketplace, and just because VBA is not (and was never advertised as) an OO language, does not make it any less viable as a programming environment.

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Also, remember that Access and VBA have been around for a LONG time - I started using Access (Access 2) back in 1990, with AccessBasic - (the earlier version of what was to grow into VBA) - long before OO concepts were being tossed around freely - oh sure, there might have been SmallTalk, and C++, but those languages were totally beyond the range of experience or use of the typical Access user.

AccessBasic was based on BASIC, as was Visual Basic - and Visual Basic did not gain even the rudiments of OO concepts until VB4, in about 1994 or 1995.  So the history of AccessBasic and VBA would preclude almost any implementation of full OO concepts.  Just look at the howling and snarling and loud gnashing of teeth that accompanied the introduction of TRUE Obejct Oriented Concepts - the whole nine-yards - with the release of Visual Studio.NET and the accompanying 'culture shock' that hit the casual VB users like a ton of bricks - and they saw themselves as true 'programmers' - Access users rarely see themselves as Programmers - in the strict sense of the word.  Trying to get Access 'developers' to learn and comprehend the principles of OO development would fail dismally, and with it would go one of the most successful Desktop Database tools ever created.


Well, I want to comment on this.

Wile VB isn't an OOP language, it must be said that it's clearly OLO. Whenever I teach VBA, I clearly distinguish between the "scripting language" or "interpreted language" in which we write our code, and the very powerful objects that are at our dispsal. And VB is clearly "object library oriented" because you can write those beautiful and incredibly succinct lines of code _using_ objects.

Before you start to create your own objects, study in detail what you can do with the existing: Recordsets, Fields, Forms, Controls, Connections, VBComponents, Errors, not to mention all the available ActiveX components. Integrate this with the event-driven paradigm, and VB becomes a good platform. For small applications, for quickly changing applications, for prototyping and for teaching.

But perhaps the best question is: what is it exactly that you are missing? If you are looking to define a new data type, if you want to overload an operator, or if you want to modify an existing class method, then you need to look elsewhere. But if you want to create an object that contains an encapsulated form and a recordset, a set of classes to automate HTML exports, or create a new spinner button control, you can do that in VB, but perhaps not exactly in the way you are used to.

Another problem you are facing is that Access is a three-headed beast. Access per se is merely a decent but far from perfect database and GUI design platform, and a runtime library. It interfaces with VB mainly through exposed user and database events. The database engine also interacts with VB, by a shared functions library and by several object libraries. So that neither the interface nor the data are really part of VB. How can you have any serious OO support in a language that controls neither?

So again, tell us one or two of the things you are struggling with. We might stop the arguing and start being useful ;)

Well said.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.