ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End SubRecordset ......................................................................................................
ADO recordsets represent sets of records in a database, much like DAO recordsets, though their
attributes are more generic. An ADO recordset can be based on a table, query, SQL statement, or
Command object. The TestForwardReadOnlyprocedure listed here uses a saved select query
as the recordset source:Private Sub TestForwardReadOnly()On Error GoTo ErrorHandlerDim cnn As ADODB.Connection
Dim rst As ADODB.RecordsetCreate a connection to the current database.Set cnn = CurrentProject.Connection
Set rst = New ADODB.RecordsetCreate a recordset based on a select query.rst.Open Source:=”qryCompanyAddresses”, _
ActiveConnection:=cnn.ConnectionString, _
CursorType:=adOpenForwardOnly, _
LockType:=adLockReadOnlyIterate through the query, and print values from fields to the Immediate window.Do While Not rst.EOF
Debug.Print “Company ID: “ & rst![CompanyID] _
& vbCrLf & vbTab & “Category: “ _
& rst![Category] _
& vbCrLf & vbTab & “Company Name: “ _
& rst![Company] & vbCrLf
rst.MoveNext
LoopErrorHandlerExit:Part II Writing VBA Code to Exchange Data between Office Components