DrewDog_21
Sep 21st, 2000, 12:37 PM
I am working on a routine to clean the database of all junk
data. Example: Table A and Table B have a 1 to Many
relation, and I want to delete the records from Table A that
have no entry in Table B. I could do this with two
recordsets by comparing the values, but the tables are huge
and that takes forever. I thought I could use some error
handling and Resume Next statements, but those are giving
me problems on the .Delete and .MoveNext statements.
What happens is the loop arrives at a record that has
related records, attempts to delete it, skips to the error
handler, then returns to the .MoveNext line. But then the
error happens again, and the recordset stays permanently on
that record :rolleyes:
I can't use a line like Resume SkipUpdate because I want to
perform this process on many tables. Any suggestions will
be appreciated!
On Error GoTo Database_Error
With rsMyTable
If .RecordCount <> 0 Then
.MoveFirst
Do Until .EOF
.Delete 'the code gets hung up on these two lines
.MoveNext
Loop
End If
.Close
End With
Exit Sub
Database_Error:
If Err.Number = -2147217887 Then 'record can't be deleted
Resume Next
End If
End Sub
[Edited by DrewDog_21 on 09-21-2000 at 01:50 PM]
data. Example: Table A and Table B have a 1 to Many
relation, and I want to delete the records from Table A that
have no entry in Table B. I could do this with two
recordsets by comparing the values, but the tables are huge
and that takes forever. I thought I could use some error
handling and Resume Next statements, but those are giving
me problems on the .Delete and .MoveNext statements.
What happens is the loop arrives at a record that has
related records, attempts to delete it, skips to the error
handler, then returns to the .MoveNext line. But then the
error happens again, and the recordset stays permanently on
that record :rolleyes:
I can't use a line like Resume SkipUpdate because I want to
perform this process on many tables. Any suggestions will
be appreciated!
On Error GoTo Database_Error
With rsMyTable
If .RecordCount <> 0 Then
.MoveFirst
Do Until .EOF
.Delete 'the code gets hung up on these two lines
.MoveNext
Loop
End If
.Close
End With
Exit Sub
Database_Error:
If Err.Number = -2147217887 Then 'record can't be deleted
Resume Next
End If
End Sub
[Edited by DrewDog_21 on 09-21-2000 at 01:50 PM]