BatchCollisionCount Property
Applies To
Dynamic-Type Recordset object, Dynaset-Type Recordset object, Forward-Only–Type Recordset object, Recordset object, Snapshot-Type Recordset object.
Description
Returns the number of records that did not complete the last batch update (ODBCDirect workspaces only).
Return Value
The return value is a Long that indicates the number of failing records, or 0 if all records were successfully updated.
Remarks
This property indicates how many records encountered collisions or otherwise failed to update during the last batch update attempt. The value of this property corresponds to the number of bookmarks in the BatchCollisions property.
If you set the working Recordset object's Bookmark property to bookmark values in the BatchCollisions array, you can move to each record that failed to complete the most recent batch Update operation.
After the collision records are corrected, a batch-mode Update method can be called again. At this point DAO attempts another batch update, and the BatchCollisions property again reflects the set of records that failed the second attempt. Any records that succeeded in the previous attempt are not sent in the current attempt, because they now have a RecordStatus property of dbRecordUnmodified. This process can continue as long as collisions occur, or until you abandon the updates and close the result set.
Example
This example uses the BatchCollisionCount property and the Update method to demonstrate batch updating where any collisions are resolved by forcing the batch update.
Sub BatchX()
Dim wrkMain As Workspace
Dim conMain As Connection
Dim rstTemp As Recordset
Dim intLoop As Integer
Dim strPrompt As String
Set wrkMain = CreateWorkspace("ODBCWorkspace", _
"admin", "", dbUseODBC)
' This DefaultCursorDriver setting is required for
' batch updating.
wrkMain.DefaultCursorDriver = dbUseClientBatchCursor
Set conMain = wrkMain.OpenConnection("Publishers", _
dbDriverNoPrompt, False, _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers")
' The following locking argument is required for
' batch updating.
Set rstTemp = conMain.OpenRecordset( _
"SELECT * FROM roysched", dbOpenDynaset, 0, _
dbOptimisticBatch)
With rstTemp
' Modify data in local recordset.
Do While Not .EOF
.Edit
If !royalty <= 20 Then
!royalty = !royalty - 4
Else
!royalty = !royalty + 2
End If
.Update
.MoveNext
Loop
' Attempt a batch update.
.Update dbUpdateBatch
' If there are collisions, give the user the option
' of forcing the changes or resolving them
' individually.
If .BatchCollisionCount > 0 Then
strPrompt = "There are collisions. " & vbCr & _
"Do you want the program to force " & _
vbCr & "an update using the local data?"
If MsgBox(strPrompt, vbYesNo) = vbYes Then _
.Update dbUpdateBatch, True
End If
.Close
End With
conMain.Close
wrkMain.Close
End Sub