Using Microsoft ActiveX Data Objects (ADO) via Visual Basic

Microsoft Corporation

May 1998

Abstract

This article discusses how to take advantage of Microsoft® ActiveX® Data Objects (ADO) with Microsoft® Visual Basic® version 5.0. ADO 2.0 has been integrated into Visual Basic 6.0. See the Visual Basic documentation for more information.

What Is ADO?

ActiveX Data Objects is a programming model, which means that it is not dependent upon any given back-end engine. ADO can access data through any OLE DB provider. The following OLE DB providers ship with Microsoft Data Access Components (MDAC) 2.0:

ODBC drivers are supported through the OLE DB Provider for ODBC, often referred to as Kagera.

The ADO object model consists of seven objects:

ADOR is a subset of this ADO object model. ADOR provides only the Recordset and Field objects.

Installing ADO on Your Machine

With Visual Basic 6.0, ADO installs automatically. If you wish to use ADO 2.0 with a version of Visual Basic earlier than 6.0, you must follow these instructions:

  1. To properly install ADO on your machine, you will need to install Microsoft Data Access Components (MDAC) 2.0, or the Microsoft Data Access SDK 2.0. (Microsoft Data Access Components and the Data Access SDK are available free for download from the Microsoft Data Access Web site, http://www.microsoft.com/data/.)

  2. After ADO is installed on your machine, simply create a new project inside Visual Basic, click References on the Projects menu, and then select Microsoft ActiveX Data Objects (2.0) Library.

ADO vs. DAO

If you include references to both ADO and DAO in the same project, you will have some difficulty. Both use the same object named Recordset, so the following code is ambiguous:

   Dim r as recordset

To specify which object model to use, include a qualifier in front:

   Dim s As ADODB.Recordset
   Dim t As DAO.Recordset

For More Information

For more information, see the Microsoft Knowledge Base article Q168342 "INFO: Choosing the Right VB5 Data Access Interface (ADO/DAO/RDO)."