What Is Automation?

team lib

Even though you may not realize it, you've already seen automation in action, as using any standalone object is a form of automation. Remember when you went into the References and selected the DAO Library and then defined a variable as type Recordset ? Well, that's just using an existing object.

So, in VBA and programming terms, automation is just the use of other objects. At the application level that means using such things as Outlook to send mail messages, or perhaps embedding an Excel chart on an Access form. What these do is just use some existing functionality, but instead of this functionality coming from a class, or a small object, it comes from an application. So you must get into the habit of thinking of everything as an object, even applications.

There are two descriptions that you might hear about when dealing with automation, and they are Automation Server and Automation Client.

Automation used to be called OLE Automation, so you might hear of OLE Servers and OLE Clients, but these days it's generally just referred to as Automation.

An Automation Server is the object you are using (it has nothing to do with physical machines), and an Automation Client is the one using the object. So, if you have some VBA code in an Access module, and that code uses Microsoft Excel, then Access is the Client, and Excel is the Server.

Interfaces and Object Models

Objects have interfaces , and these define what parts of the object the programmer can see - this usually means the methods , properties, and events. Remember when we looked at classes the Public procedures became methods and the Property procedures became properties? That's the interface - the view the user of the object has. All of the Private procedures and Private variables are part of the object, but they are not part of the interface, because they cannot be seen outside of the object.

An object model is just another way of saying interface, and is usually a diagram showing the objects and collections. For example, a portion of the DAO object model is shown below:

click to expand

The Objects are shown shaded and the Collections are in white. This sort of diagram allows us to clearly see the hierarchy of objects, and makes it easier to find our way around the objects. For example if we have a Recordset object we know it has a Fields collection. This means we can instantly know that code like this will work:

   For Each objField in objRec.Fields     Next   

Understanding the object model is paramount to using automation. All of the Office applications have an object model, but we won't be including them in the book, as they are far too large. They are well covered in the Office documentation (make sure you install the VBA Help for all of the applications), and we've also included the most relevant sections of them on the CD.

Important 

Of course, Wrox have a range of Office VBA books available - check out www.wrox.com for more details.

 
team lib


Beginning Access 2002 VBA
Beginning Access 2002 VBA (Programmer to Programmer)
ISBN: 0764544020
EAN: 2147483647
Year: 2003
Pages: 256

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net