HandsOn Retrieving Field Values

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

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

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

Sub ReadField()

Dim conn As ADODB.Connection Dim rst As ADODB.Recordset

Set conn = CurrentProject.Connection

Set rst = New ADODB.Recordset rst.Open "Select * from Employees", conn, adOpenStatic

Do While Not rst.EOF

Debug.Print rst.Fields("LastName").Value rst.MoveNext Loop rst.Close Set rst = Nothing conn.Close Set conn = Nothing End Sub

0 0

Post a comment