Creating a button to delete records in certain date period?

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
 
V

Van T. Dinh

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top