Delete button

wayney2507

New member
Local time
Today, 23:27
Joined
Apr 29, 2009
Messages
9
I have a table "Jobsheet" with a field "Date" within it.

I'd like to put a button on a form so that when clicked, it deletes all records with a date which is 90 days older than todays date.

Help please?
 
Try

CurrentDb.Execute "DELETE * FROM TableName WHERE FieldName < DateAdd('d', -90, Date())"

A field named "date" isn't a good idea, as it can conflict with the built-in Date() function.
 
Ah i found out how do it the easy way. Make a 'delete query' using criteria "<Date()-90"

Thanks for the help though.
 
Ah i found out how do it the easy way. Make a 'delete query' using criteria "<Date()-90"

This is not really any different from using DoCmd.RunSQL, as you have to call DoCmd.OpenQuery, and if you don't want to bother your users with the confirmation messages, you have to turn off SetWarnings and then turn it back on.

So, the exact same problems adduced for the other solutions are present the DoCmd.RunQuery, and the solution I posted is designed to avoid those problems.
 

Users who are viewing this thread

Back
Top Bottom