Working with Recordsets

The first thing you want to do with a recordset is open it, of course. In order to open a recordset, you must specify, with the Recordset object, what information you want, where your information is located, and how to open your information.

The Open Method

The following syntax describes the Open method of the Recordset object:

Recordset.Open [Source], [ActiveConnection], [CursorType], _
               [LockType], [Options]

Notice that all of the parameters of the Open method are optional. The parameters all relate directly to the respective properties of the Recordset object. You can set their values through the corresponding parameter or property. However, specifying the parameter will override previously set properties. In addition, these properties are read/write while the Recordset object is closed but read-only once the object has been opened.

Setting the Source property of the Recordset object indicates the information you wish to open in your recordset. The ActiveConnection property tells the Recordset object where it can find the information that you want to open. Both the CursorType and LockType properties tell the Recordset how to open and use the information in the recordset. The following code opens a Recordset object and sets its properties:

rst.Source = "Authors"
rst.ActiveConnection = "DSN=BiblioDSN"
rst.CursorType = adOpenKeyset
rst.LockType = adLockOptimistic

' do something here

As you can see, there is not much involved with opening ...

Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.