Defining a connection

Although a recordset is invisible to a human, it's a real object that VBA can manipulate. You can think of a recordset as sort of an invisible, ghost image of a datasheet that invisible VBA can manipulate (at lightning speeds, we might add). But before VBA can even create such a ghost, it needs to know where the tables for the ghost reside. That's where the first two statements, shown as follows, come in:

Dim cnnl As ADODB.Connection

Set cnnl = CurrentProject.Connection

The first line declares to all VBA statements to all lines of code that follow that it is creating a thing named cnnl that will be an ADODB connection. ADO, which stands for ActiveX Data Objects, is the object model we use to create recordsets throughout this book. ADO isn't built into Access: It's an object library that many programs use to manipulate data in Access tables. For example, you could write VBA code in a Microsoft Excel or Word macro to grab data from an Access table, if you use ADO.

To use ADO in VBA, you need to set a reference to Microsoft ActiveX Data Object Library in the References dialog box. Like all object libraries, ADO is a highly organized collection of objects, properties, and methods that you can boss around with VBA to make databases do things. And, like all other things you can manipulate with VBA, ADO objects, properties, and methods are found in the Object Browser and also in the VBA Help.

Was this article helpful?

0 0

Post a comment