Skip to Content
Access™ 2007 VBA Programmer's Reference
book

Access™ 2007 VBA Programmer's Reference

by Teresa Hennig, Rob Cooper, Geoffrey Griffith, Armen Stein
May 2007
Intermediate to advanced
1152 pages
30h 53m
English
Wrox
Content preview from Access™ 2007 VBA Programmer's Reference

13.2. Why Use Classes?

From a coding perspective, the only real difference between using the built-in Access or VBA objects and the ones you write yourself, is that you have to instantiate your custom objects. Other than that, there's no difference at all.

There is a learning curve associated with creating your own class objects, but once learned, the major benefit is much simpler and more manageable code. Let's say you are using API functions in your application. You can create your own interface that hides the complexity of the API functions with a class. By this same token, classes are also very useful if you are writing code that will be used by other developers.

Also, while you can instantiate the built-in objects, using the Dim construct, you don't always have to. For example, to expose the Name property of a Table object, either of the following examples will work.

MsgBox DBEngine(0)(0).TableDefs(1).Name

Set tdf = DBEngine(0)(0).TableDefs(1)

Admittedly, if you've never written classes before, using them requires a different way of thinking at first. Once you become familiar with the concepts, you'll find great benefit in their usage. Once written, classes provide increased reusability and a layer of abstraction that enables you to focus more on business logic or rules. The end result is code that is easier to use. The Recordset class in DAO is an example of a class that is used quite frequently. So why not write your own?

Now having just expounded the virtues of adopting ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Excel® 2007 VBA Programmer's Reference

Excel® 2007 VBA Programmer's Reference

John Green, Stephen Bullen, Rob Bovey, Michael Alexander
Access 2003 VBA Programmer's Reference

Access 2003 VBA Programmer's Reference

Patricia Cardoza, Teresa Hennig, Graham Seach, Armen Stein
Microsoft® Access® 2010 Programmer's Reference

Microsoft® Access® 2010 Programmer's Reference

Teresa Hennig, Rob Cooper, Geoffrey L. Griffith, Jerry Dennison

Publisher Resources

ISBN: 9780470047033Purchase book