473,394 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Code to delete all queries not working right

Using A2003. I'm attempting to delete all queries in an mdb. I was
experimenting with the following coding and discovered that it deletes
exactly half the queries each time it's run. If I have 100 queries,
then it deletes 50 the first time it's run. The next time, it deletes
25, and so on. What modifications do I need to make it delete all
queries in one execution? Thanks for any help or advice.

dbs.QueryDefs.Refresh
For Each qdf In dbs.QueryDefs
dbs.QueryDefs.Delete qdf.name
Next

Feb 8 '06 #1
6 4333
Go backwards
air code
For z= dbs.QueryDefs.Count-1 to 0 Step - 1
dbs.QueryDefs.Delete dbs.QueryDefs(z).Name
Next z

Feb 8 '06 #2
Yep, that did it. Thanks!

Feb 8 '06 #3
I recommend that you spend a few minutes thinking about why backwards
works as you wish and forward does not, for your own edification and
because there are several Access collections that behave in this
fashion, and also because if you don't, sometime when you are
demonstrating to a client, the Gods of Access will punish you by
arranging for an error connected with this behaviour to occur.

Feb 8 '06 #4
I recommend that you spend a few minutes thinking about why backwards
works as you wish and forward does not, for your own edification and
because there are several Access collections that behave in this
fashion, and also because if you don't, sometime when you are
demonstrating to a client, the Gods of Access will punish you by
arranging for an error connected with this behaviour to occur.

Feb 8 '06 #5
Lyle Fairfield <ly***********@aim.com> wrote:
: I recommend that you spend a few minutes thinking about why backwards
: works as you wish and forward does not, for your own edification and
: because there are several Access collections that behave in this
: fashion, and also because if you don't, sometime when you are
: demonstrating to a client, the Gods of Access will punish you by
: arranging for an error connected with this behaviour to occur.

A backward solution:
Go backwards
air code
For z= dbs.QueryDefs.Count-1 to 0 Step - 1
dbs.QueryDefs.Delete dbs.QueryDefs(z).Name
Next z

I thought about it.
This code is even airier because I haven't looked up the syntax for
a VBA while statement

A 'static' solution:
While dbs.QueryDefs.Count > 0
dbs.QueryDefs.Delete dbs.QueryDefs(0).Name
Loop

--thelma
Feb 8 '06 #6
You could Wend your way through the collection that way, I think.

Feb 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: pmatos | last post by:
Hi all, I've been having questions about strings, references, initializations... I've created code (which will not compile due to a reference problem) and I'd like comments on why this won't...
3
by: NeilAnderson | last post by:
I'm a fairly new user of access & I've never had any training, so I'm wondering if I'm doing the right thing here, or if it matter at all. I'm building a database for room booking purposes and I'm...
2
by: Greg Strong | last post by:
Hello All, I've written code in a test database with test data. Everything seems to be working except compact database in VB code per http://www.mvps.org/access/general/gen0041.htm. The reason I...
6
by: deko | last post by:
Now that users are handy at importing tables from an Excel spreadsheet, I've discovered a very dangerous problem. If the user decides to name the imported table the same name as an existing...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
1
by: austin1539 | last post by:
-Access 2002 -Windows XP Pro Trying to run a DELETE Query to delete each entry in the table 'Data' where the field 'AssocID' matches the field 'AssocID' in the table 'Queries' and the date is...
3
by: Phil Stanton | last post by:
I have a form based on a complex query (Lots of tables) If I delete a record, everything appears to be OK. Get the message "Youa are about to delete 1 record ....". I say yes. The record count...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.