Microsoft Office Tutorials and References
In Depth Information
Chapter 5: Using SQL and Recordsets
Figure 5-1:
dialog box.
Because ADO is evolving quickly, you’ll likely find several versions of the
ActiveX Data Objects Library in your References dialog box. Select only the
most recent one — the one with the highest version number. Then click OK.
Creating quick and easy recordsets
If your goal is to create a recordset that contains all the fields and records
from a single table in your database, the job is fairly straightforward. Just
type the following code, exactly as shown, in a procedure, but replace
tableName with the name of the table that you want to open:
Dim myConnection as ADODB.Connection
Set myConnection = CurrentProject.Connection
Dim myRecordset as New ADODB.Recordset
myRecordset.ActiveConnection = myConnection
myRecordset.Open “ tableName ”, , adOpenStatic, adLockOptimistic
If you don’t yet know how to type code in a procedure, see Chapter 2 of this
After all the lines execute, the myRecordset object variable refers to all the
fields and records in whatever table you specified as tableName in the last
line of code.
Understanding ADO recordset properties and methods
Most ADO recordsets support the following methods, which allow you to
manipulate the data in the recordset with VBA code:
.AddNew: Adds a new, blank record to the recordset
.MoveFirst: Moves the cursor to the first record in the recordset
.MoveNext: Moves the cursor to the next record in the recordset
.MovePrevious: Moves the cursor to the previous record in the recordset
Search JabSto ::

Custom Search