delete query

NigelShaw

Registered User.
Local time
Today, 15:03
Joined
Jan 11, 2008
Messages
1,575
Hi,

i have set up a delete query to delete items ticked on a query. the form related to the query only shows the items with a "False" value in the criteria. anything set as "true" ( ticked ) is reserved for deleting. the delete query looks at the query and selects all items set to true. it works ok but i dont know how to get this work automatically without going trough the access prompts of deleting.

can this be done with code behind a button whereas if clicked, it runs the query and deletes all of the true items?


thanks,

NS
 
If you want to use code, it would be:

Code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "QueryName"
DoCmd.SetWarnings True
 
It sounds like you're using a DoCmd here, in which case you'd put it like this:

DoCmd.SetWarnings False
--- Your DoCmd for the delete query here ---
DoCmd.SetWarnings True

The other way around this is to use CurrentDb.Execute, which doesn't require you to turn off the warnings:

CurrentDb.Execute "DELETE * FROM YourTable WHERE MarkForDeleteField = True;"

I prefer the second way because if you forget to do the DoCmd.SetWarnings True, then warnings are off until you turn them back on or until Access is closed and reopened. This means that other actions where you may want a warning will not give you one. With such a simple query, you also do not need to store a query for deleting the records marked for deletion, meaning one less object to track in the DB window.
 

Users who are viewing this thread

Back
Top Bottom