Access.2007.VBA.Bibl..

(John Hannent) #1
strLockType = Switch(rst.LockType = _
adLockOptimistic, _
“Optimistic (“ & adLockOptimistic & “)”, _
rst.LockType = adLockReadOnly, “Read-only (“ _
& adLockReadOnly & “)”, _
rst.LockType = adLockBatchOptimistic, _
“BatchOptimistic (“ _
& adLockBatchOptimistic & “)”, _
rst.LockType = adLockPessimistic, _
“Pessimistic (“ _
& adLockPessimistic & “)”)

Debug.Print “Recordset cursor/lock type: “ _
& strCursorType & “, “ & strLockType & vbCrLf

Iterate through the recordset, and print values from fields to the Immediate window.


With rst
.MoveFirst
Do While Not .EOF
Debug.Print “Swedish Company name: “ _
& ![CompanyName] _
& vbCrLf & vbTab & “Contact name: “ _
& ![ContactName] _
& vbCrLf & vbTab & “City: “ & ![City] _
& vbCrLf
rst.MoveNext
Loop
End With

ErrorHandlerExit:

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

Working with Access Data 5

Free download pdf