REFERENCING THE TYPE LIBRARIES

Before seeing how to use these collections and objects, you need to know how to reference the object model libraries for use. The object models are found in type libraries in the file system. A type library contains the information about the object models such as the collections, properties, and methods. Referencing the type libraries isn't too hard a task, but is still very important.

The first type library, ActiveX Data Objects 2.1, is referenced by default for new databases. The others have to be added as needed. To reference the other two object models, choose References from the VBE's Tools menu. You then have to find the type libraries for the object models and select them. The type library names are as follows:

  • Microsoft ActiveX Data Objects 2.1 Library (already referenced)

  • Microsoft ADO Ext. 2.1 for DDL and Security Library

  • Microsoft Jet and Replication Objects 2.1 Library

You can see these libraries, as well as the Microsoft DAO 3.6 Objects Library, in Figure 6.5.

Figure 6.5. Registering the object model type libraries.


Note

You can see from Figure 6.5 that the DAO library has been moved, using the up and down arrows on the References dialog, to follow the ADO libraries. VBA uses the objects specified in code from the library that occurs first. For example, ADO and DAO both have a Recordset object. When you declare a variable of type Recordset without specifying the library, like this,

Dim rstTest as Recordset

VBA will figure the Recordset object to be DAO if the DAO library is first.


Tip

You can use both ADO and DAO libraries in the same application without worrying about the order of libraries in the references. This is great when you're converting applications from DAO to ADO. To use all libraries and not worry about the order of reference, you must prefix your objects with the library they come with. Here are some examples, with the specific library types:

Dim rstTestDAO as DAO.Recordset
Dim rstTestADO as ADODB.Recordset
Dim catTest as ADOX.Recordset
Dim jeCurr as JRO.JetEngine

Although not all objects are shared between the libraries, it's a good idea to specify the library while getting used to the objects.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.83.150