Public Sub main()
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
' Step 1
conn.Open "DSN=pubs;uid=sa;pwd=;database=pubs"
' Step 2
Set cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * from authors"
' Step 3
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenStatic, adLockBatchOptimistic
' Step 4
rs!au_lname.Properties("Optimize") = True
rs.Sort = "au_lname"
rs.Filter = "phone LIKE '415 5*'"
rs.MoveFirst
Do While Not rs.EOF
Debug.Print "Name: " & rs!au_fname & " "; rs!au_lname & _
"Phone: "; rs!phone & vbCr
rs!phone = "777" & Mid(rs!phone, 5, 11)
rs.MoveNext
Loop
' Step 5
conn.BeginTrans
'Step 6, part A
On Error GoTo ConflictHandler
rs.UpdateBatch
On Error GoTo 0
conn.CommitTrans
Exit Sub
'Step 6, part B
ConflictHandler:
rs.Filter = adFilterConflictingRecords
rs.MoveFirst
Do While Not rs.EOF
Debug.Print "Conflict: Name: " & rs!au_fname; " " & rs!au_lname
rs.MoveNext
Loop
conn.Rollback
Resume Next
End Sub
This is the end of the Visual Basic tutorial.