Close the Recordset and Connection objects.
If Not rst Is Nothing Then
If rst.State = adStateOpen Then
rst.Close
Set rst = Nothing
End If
End If
If Not cnn Is Nothing Then
If cnn.State = adStateOpen Then
cnn.Close
Set cnn = Nothing
End If
End If
Exit Sub
ErrorHandler:
MsgBox “Error No: “ & Err.Number _
& “; Description: “ & Err.Description
Resume ErrorHandlerExit
End Sub
ADO recordsets have four types of cursors (cursors in ADO are roughly equivalent to the DAO
recordset types), as described in the following two tables. Each cursor type supports different
methods depending on the setting of the LockTypeargument. The two most commonly used lock
types are the read-only (named constant: adLockReadOnly) and optimistic (named constant:
adLockOptimistic) type. Table 5.4 lists the ADO cursor types, with their numeric equivalents,
and Table 5.5 lists the most commonly used cursor and lock type combinations for working with
Access data.
TABLE 5.4
ADO Recordset Cursor Type Named Arguments
Cursor Type Named Constant Numeric Value
Dynamic adOpenDynamic 2
Keyset adOpenKeyset 1
Static adOpenStatic 3
Forward-only adOpenForwardOnly 0
Working with Access Data 5