Layered Do...Loop problem

P

Pendragon

(Access 03)
I have two recordsets which are getting the appropriate data. The first
recordset, rsAddress, is a list of IDs (and other data) found in the second
recordset, rsAltAddress, which need to be deleted from the second recordset.

set rsAltAddress = MyDB.OpenRecordset("Select * from IndivsAltAddress Order
By IndivsAltAddress.IndivID")

In IndivsAltAddress, IndivID is an indexed field with duplicates allowed.

What I need to do is for each record in rsAddress, go through all records in
rsAltAddress and if the IndivID in each is a match, then delete the entire
record from rsAltAddress.

In the code below, I get through the first iteration of the embedded
DO...LOOP. After the .MoveNext and the LOOP, upon entering the condition
statement again, the loop exits and errors with Error 3167: Record deleted.

I've looked at and varied the statements so much I'm now completely lost.
Guidance is truly appreciated.

The code:

rsAddress.MoveFirst
rsAltAddress.MoveFirst
With rsAddress
Do While Not rsAddress.EOF
With rsAltAddress
Do While Not rsAltAddress.EOF
If rsAddress("IndivID") = rsAltAddress("IndivID") Then 'THIS IS
WHERE IT ERRORS ON THE SECOND ITERATION
.Delete
End If
.MoveNext
Loop
End With
rsAddress.MoveNext
Loop
End With

Thanks!!!!
 
P

Pendragon

After throwing in a couple message boxes to display the ID from both
recordsets, I found out that the error is on rsAddress("IndivID") in the
condition statement. This is very odd since rsAltAddress is the recordset
from which records are being deleted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top