how can I delete records from a database(access) where the user specifies on the form through a textbox the number of days worth of data to leave like 7 days to leave only data created in th elast 7 days in the table?
Printable View
how can I delete records from a database(access) where the user specifies on the form through a textbox the number of days worth of data to leave like 7 days to leave only data created in th elast 7 days in the table?
You'd need to have some sort of field in each record that has when the record was created, then use some simple DELETE SQL to remove all those that fall before Date - 7 days
To figure out what date was 7 days from the current date is easy.VB Code:
Dim Today As Date Dim LastWeek As Date Today = Now LastWeek = Today - 7 MsgBox Format(Today, "mm/dd/yyyy") MsgBox Format(LastWeek, "mm/dd/yyyy")
in the database the fields are SiteID, URL,Date,Retaindays
date = the date it was entered
i'm extremly new to sql but learning
see chris I told you ya help me alot :)
First things first, I suggest you rename the "Date" field to something else, like "RecordDate" because Date is a reserved word and I find it causes problems if you do that.
Example of some delete SQL...
VB Code:
DELETE FROM [[i]TableName[/i]] WHERE [RecordDate] < #" & DateAdd("d",-7,Date) & "#;