Results 1 to 5 of 5

Thread: Database help needed

  1. #1
    egiggey
    Guest

    Database help needed

    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?

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    To figure out what date was 7 days from the current date is easy.
    VB Code:
    1. Dim Today As Date
    2. Dim LastWeek As Date
    3. Today = Now
    4. LastWeek = Today - 7
    5. MsgBox Format(Today, "mm/dd/yyyy")
    6. MsgBox Format(LastWeek, "mm/dd/yyyy")

  4. #4
    egiggey
    Guest
    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

  5. #5
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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:
    1. DELETE FROM [[i]TableName[/i]] WHERE [RecordDate] < #" & DateAdd("d",-7,Date) & "#;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width