Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem deleteing all queries

Status
Not open for further replies.

TJones8

Technical User
Apr 16, 2002
77
GB
Hi all, i knocked up a little bit of code that should delete all queires in my db :

Code:
Dim qd As QueryDef
For Each qd In CurrentDd.QueryDefs
    CurrentDd.QueryDefs.Delete qd.Name
Next qd
CurrentDd.QueryDefs.Refresh
Set qd = Nothing

but this only deletes half of my queries, it seems to skip every other query. Eg:
qry1
qry2
qry3
qry4
the code will delete qry1 and qry3 but not qry2 or qry4.

This holds true no matter how many queries there are, it wil only delete half of them.

TIA

Tim if at first you don't succeed, get a 10lb lump hammer
 
Hi

This is because you are interating through the collection of querydefs, but in the interation you are changing the collection (by deleting an entry from it





Hope this helps

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove SPAMNOT to use
 
I've been using this code for deleting all queries:

Dim q As QueryDef
Do While CurrentDb.QueryDefs.Count > 0
CurrentDb.QueryDefs.Delete CurrentDb.QueryDefs(0).Name
Loop
--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
I guessed as much - and i came up with this :
Code:
Do While .QueryDefs.Count > 0
    .QueryDefs.Delete .QueryDefs(0).Name
Loop
which seems to do the job.
Typical though - as soon as i post this problem i figure it out by myself :)
Thx anyways if at first you don't succeed, get a 10lb lump hammer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top