dwhawley
Jul 30th, 2000, 10:13 AM
i'm looking for a method of removing duplicate records from a recordset. my first attempt went something like the following:
'establishes connection
CreateConnection
'opens the recordset that contains all records, incl all dups
EstMasterRS
'query the main recordset for duplicates
Do Until rsFF.EOF = True And rsFF.BOF = True
'set the variables holding variables equal to current record
strHold0 = rsFF.Fields(0)
strHold1 = rsFF.Fields(1)
strHold2 = rsFF.Fields(2)
'query all records that have strHold0 as a control no
sqlControl1 = "UPDATE tblFF SET delete = 1, reviewed = 1" & _
" WHERE FF_ControlNo = '" & strHold0 & "' AND" & _
" FF_Desc = '" & strHold1 & "' AND" & _
" FF_CCUnit = '" & strHold2 & "'"
'slow
rsControl1.Open sqlControl1, conEquip, adOpenForwardOnly, adLockOptimistic
rsControl1.MoveNext
'if recordcount = 1 then the record is unique and marked reviewed
If rsControl1.EOF = False Or rsControl1.BOF = False Then
'if recordcount > 1 then then the rs is searched for dup info
'slow
rsControl1.Fields(4) = vbTrue
'rsControl1.Update
rsControl1.MoveNext
Do Until rsControl1.EOF = True
'if criteria is true than this dup info. mark for delete
If strHold1 = rsControl1.Fields(1) And _
strHold2 = rsControl1.Fields(2) Then
rsControl1.Fields(3) = vbTrue
rsControl1.Fields(4) = vbTrue
'rsControl1.Update
Else
'if criteria is not true than this is unique info
rsControl1.Fields(4) = vbTrue
'rsControl1.Update
End If
rsControl1.MoveNext
Loop
End If
'requery master rs because source has changed
'slow
rsFF.Requery
'update status
rsControl1.UpdateBatch
rsControl1.Close
Loop
all lines preceded with "slow" are slowing down my program (duh! :) ). is there a more efficient way of doing this? i have roughly 60,000 records to deal with and the above program took 14 hours to process less than 25% of them. ideally i would like to be able to do all of my updating from one recordset, but i have been unable to figure out how. any suggestions?
'establishes connection
CreateConnection
'opens the recordset that contains all records, incl all dups
EstMasterRS
'query the main recordset for duplicates
Do Until rsFF.EOF = True And rsFF.BOF = True
'set the variables holding variables equal to current record
strHold0 = rsFF.Fields(0)
strHold1 = rsFF.Fields(1)
strHold2 = rsFF.Fields(2)
'query all records that have strHold0 as a control no
sqlControl1 = "UPDATE tblFF SET delete = 1, reviewed = 1" & _
" WHERE FF_ControlNo = '" & strHold0 & "' AND" & _
" FF_Desc = '" & strHold1 & "' AND" & _
" FF_CCUnit = '" & strHold2 & "'"
'slow
rsControl1.Open sqlControl1, conEquip, adOpenForwardOnly, adLockOptimistic
rsControl1.MoveNext
'if recordcount = 1 then the record is unique and marked reviewed
If rsControl1.EOF = False Or rsControl1.BOF = False Then
'if recordcount > 1 then then the rs is searched for dup info
'slow
rsControl1.Fields(4) = vbTrue
'rsControl1.Update
rsControl1.MoveNext
Do Until rsControl1.EOF = True
'if criteria is true than this dup info. mark for delete
If strHold1 = rsControl1.Fields(1) And _
strHold2 = rsControl1.Fields(2) Then
rsControl1.Fields(3) = vbTrue
rsControl1.Fields(4) = vbTrue
'rsControl1.Update
Else
'if criteria is not true than this is unique info
rsControl1.Fields(4) = vbTrue
'rsControl1.Update
End If
rsControl1.MoveNext
Loop
End If
'requery master rs because source has changed
'slow
rsFF.Requery
'update status
rsControl1.UpdateBatch
rsControl1.Close
Loop
all lines preceded with "slow" are slowing down my program (duh! :) ). is there a more efficient way of doing this? i have roughly 60,000 records to deal with and the above program took 14 hours to process less than 25% of them. ideally i would like to be able to do all of my updating from one recordset, but i have been unable to figure out how. any suggestions?