How do u automatically delete records after a set peroid of time

F

fishkabob

Hi could sum1 plz tell me how to automatically delete records after three
yrs. if sum1 could tell me the automated routine how to do this?! thx
 
S

Steve Schapel

Fishkabob,

Presumably you have a field in the table in question that identifies
when the record was first entered? If so, you can make a Delete Query,
with this in the Criteria of the date field....
<DateAdd("yyyy",-3,Date())

To make it automatic, you could use a macro or VBA procedure to run this
Delete Query. This could be done, for example, on the Open event of a
form which always opens whenever the database is opened, or some other
appropriate event. In a macro, you would use an OpenQuery action,
preceded by a SetWarnings/No action to suppress the display of the
action query confirmation prompts. In a VBA procedure, you could do
like this...
CurrentDb.Execute "DELETE * FROM YourTable WHERE YourDate
<DateAdd('yyyy',-3,Date())"
 
Top