HandsOn Opening a Recordset Directly

1. In the Visual Basic Editor window, choose Insert | Module.

2. In the module's Code window, type the OpenRst_Directly procedure shown below.

3. Choose Run | Run Sub/UserForm to execute the procedure.

Sub OpenRst_Directly() Dim rst As ADODB.Recordset

Set rst = New ADODB.Recordset With rst

.Source = "Select * From Employees" .ActiveConnection = CurrentProject.Connection .Open End With

MsgBox rst.Fields(1)

rst.Close Set rst = Nothing End Sub

You can also pass the required source and connection information to the Recordset object's Open method, as in the following example:

rst.Open "Select * From Employees", CurrentProject.Connection

Part II

0 0

Post a comment