Filtering for Updated Records

Microsoft ActiveX Data Objects (ADO)

ADO 2.5

Filtering for Updated Records

Before you call UpdateBatch, you can use the Recordset Filter property to view only those records which have been changed since the Recordset was opened or the last call to UpdateBatch. To do this, set Filter equal to adFilterPendingRecords to determine how many records will be updated, as shown below.

This example extends the previous UpdateBatch example by filtering the Recordset just before calling the UpdateBatch, showing the user which records will change and allowing her to cancel the update (using the CancelBatch method).

'BeginFilterAffected
    objRs1.Filter = adFilterPendingRecords
    objRs1.MoveFirst
    
    strMsg = "The following " & objRs1.RecordCount & " values will " & _
             "be updated. Do you wish to proceed?"
    While Not objRs1.EOF
        strMsg = strMsg & vbCrLf & objRs1(0) & vbTab & objRs1(1) & vbTab & _
                 objRs1(2) & vbCrLf
        objRs1.MoveNext
    Wend
    
    blnResp = MsgBox(strMsg, vbYesNo, "Proceed with Update?")
    If blnResp = True Then
        objRs1.UpdateBatch
    Else
        objRs1.CancelBatch
    End If
'EndFilterAffected

© 1998-2003 Microsoft Corporation. All rights reserved.