Recordset.BatchCollisionCount プロパティ (DAO)

適用先: Access 2013、Office 2013

構文

式 。BatchCollisionCount

expression: Recordset オブジェクトを表す変数。

注釈

このプロパティは、最後の一括更新を実行しているときに競合が発生したかまたは更新に失敗したレコードの数を示します。 このプロパティの値は、 BatchCollisions プロパティのブックマークの数に対応します。

作業中の Recordset オブジェクトの Bookmark プロパティを、 BatchCollisions 配列のブックマークの値に設定すると、最新のバッチ Update 操作の完了に失敗した各レコードに移動できます。

競合するレコードを修正した後、バッチモードの Update メソッドを再び呼び出すことができます。 ここで DAO はもう一度バッチ更新を試み、再び BatchCollisions プロパティに、2 回目の実行で失敗したレコードのセットが反映されます。 以前の実行が正常に終了したレコードは、 RecordStatus プロパティが dbRecordUnmodified に設定されているため、現在の実行には送信されません。 このプロセスは、競合が発生する限り続行できますが、更新を中止して結果セットを閉じることもできます。

例

この例では、 BatchCollisionCount プロパティおよび 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 
 
 ' Note: The DSN referenced below must be configured to 
 ' use Microsoft Windows NT Authentication Mode to 
 ' authorize user access to the Microsoft SQL Server. 
 Set conMain = wrkMain.OpenConnection("Publishers", _ 
 dbDriverNoPrompt, False, _ 
 "ODBC;DATABASE=pubs;DSN=Publishers") 
 
 ' The following locking argument is required for 
 ' batch updating. It is also required that a table 
 ' with a primary key is used. 
 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