Re: DAO qdfs does not delete my queries
- From: Ben <Ben@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 4 Nov 2008 19:24:00 -0800
Wow, that was great explanation. I didn't realize that. Thank you so much
Doug.
Ben
--
"Douglas J. Steele" wrote:
When deleting objects from collections such as the QueryDefs collection, you.
need to work backwards from the end of the collection.
In other words, rather than:
Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Set dbCurr = CurrentDb
For Each qdfCurr In dbCurr.QueryDefs
Next qdfCurr
you should use
Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Dim lngLoop As Long
Set dbCurr = CurrentDb
For lngLoop = (dbCurr.QueryDefs.Count - 1) To 0 Step -1
Set qdfCurr = dbCurr.QueryDefs(lngLoop)
Next lngLoop
The reason for this is when you delete a particular QueryDef from the
collection, the pointer to the current QueryDef moves to the next QueryDef
in the collection. Since you're then issuing a Next qdfCurr command, you end
up missing the QueryDef.
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Ben" <Ben@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:56912529-6208-4985-B90D-0FFD124ECE03@xxxxxxxxxxxxxxxx
Hi all,
I have 3 queries I want to delete from my list of queries.
I used a query definition object to cycle through all my queries and
delete
them every time a query's name matches mine listed names, but for some
reason, it does not delete them all, sometimes it would delete them the
first
one and then exit the for each -next loop, sometimes it would delete two
of
the three, but never all three.
I create these queries on the fly in my code and what I had resorted to do
was at the end of my routine, I manually delete each of them one at a time
using a separate line of code each time around.
Any idea why the cycling through the query definition wouldn't work?
Thanks for sharing thoughts.
Ben
--
- References:
- DAO qdfs does not delete my queries
- From: Ben
- Re: DAO qdfs does not delete my queries
- From: Douglas J. Steele
- DAO qdfs does not delete my queries
- Prev by Date: Re: DAO qdfs does not delete my queries
- Next by Date: Re: DAO qdfs does not delete my queries
- Previous by thread: Re: DAO qdfs does not delete my queries
- Next by thread: User Access Menu
- Index(es):
Relevant Pages
|