Creating a button to delete records in certain date period?

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Please help me create a "command button" that will delete
records with a certain date period. (ie: records with
dates older then 180 days).

Your efforts are greatly appreciated!
Randy
 
Use the following code in the CommandButton_Click Event Procedure:

DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM YourTable " & _
"WHERE [RecordDate] < Date() - 180"
DoCmd.SetWarnings True

The 1st Setwarnings will delete Records silently. If you want warnings
before actual deletion, remove the SetWarnings statements.

Do can also use the Execute Method. Check Access VB Help.
 
Back
Top