I'm trying to delete all the relations to a table ("voters") in preparation for deleting it. I see a code fragment in this thread that is supposed to do the job:
http://www.access-programmers.co.uk/forums/showthread.php?t=33182
...and the code I wrote before searching seems pretty equivalent. Here's what I came up with:
And it sort of works. When run, it deletes some of the relations to that table "voters". But not all of them. If you run it again, it deletes a few more before stopping prematurely. Eventually if you run it enough times, all the relations do get deleted. But for the life of me, I can't figure out why it's taking several iterations to do the job.
I'm wondering if the delete operation somehow messes up the "For Each" construct, so that it thinks it's gone through the whole set when it hasn't? I tried inserting db.Relations.Refresh statements in several different places with no obvious change.
Any ideas?
http://www.access-programmers.co.uk/forums/showthread.php?t=33182
...and the code I wrote before searching seems pretty equivalent. Here's what I came up with:
Code:
Sub deleteRelations()
Dim db As DAO.Database
Dim n As DAO.Relation
Set db = CurrentDb
For Each n In db.Relations
If n.Table = "voters" Or n.ForeignTable = "voters" Then
db.Relations.Delete n.Name
End If
Next n
Set db = Nothing
End Sub
I'm wondering if the delete operation somehow messes up the "For Each" construct, so that it thinks it's gone through the whole set when it hasn't? I tried inserting db.Relations.Refresh statements in several different places with no obvious change.
Any ideas?