Results 1 to 10 of 10
  1. #1
    TLCTech is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    26

    How to delete records over 45 days old from current date


    I am not sure where to put a command to delete these records.
    Someone else told me to put this command in: DELETE FROM [tblRegistration] WHERE DateDiff("d", ArrivalDate, Date()) > 45

    I have attached my tlbRegistration for your viewing.

  2. #2
    TLCTech is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    26

    Attachment

    Forgot to attach the file

    tblRegistration.zip

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You can either run a Delete Query (see: https://www.fmsinc.com/microsoftacce...ete-query.html)
    or you could use a Macro, picking the "RunSQL" Action and entering that code in the SQL Statement argument.

  4. #4
    TLCTech is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    26
    Still Having issues with deleting the records

  5. #5
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    What kind of issues, exactly? Are you getting some sort of error message? If so, what?

    Depending on where you are doing this, you may need to alter your statement.

    If you are doing a Delete Query, I think you may need to alter your statement like this:
    Code:
    DELETE [tblRegistration].* FROM [tblRegistration] WHERE DateDiff("d", ArrivalDate, Date()) > 45
    If you are trying the Macro option, the DateDiff has different syntax in SQL. It shouldn't be necessary though. In subtracting two dates, the default is days, so you should just be subtract the two dates. Also, SQL uses GetDate() instead of Date().

    If you still need help please let us know which option you are pursuing, what your current code looks like, and what errors you are seeing.

  6. #6
    TLCTech is offline Novice
    Windows 10 Access 2013
    Join Date
    Dec 2015
    Posts
    26
    Thank you for the quick response, I will try it.

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    p.s. I would not delete your data at all, you never know when it might be useful or you may need to look at old records. Instead I would advocate you add a field to your table that was something like a field named 'ARCHIVE' that's yes/no and set the flag to yes (-1) when you run your process, then on your forms/reports you can set your criteria to look for only non archived records. In essence run an update query rather than a delete query.

  8. #8
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    I would not delete your data at all, you never know when it might be useful or you may need to look at old records.
    It is really hard to say for certain without knowing exactly what they are using it for.

    Personally, I have databases that have temp tables that I clear out after every use, or I have other databases which just serve as "pass-through" applications for data format conversions. In either case, there is no need to keep the data in there, so a delete query seems in perfect order.

  9. #9
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Yes I do the same, I have tables I flush and refill every week with external data but if this is a registration database being able to see who registered for which event as time goes on, to me, would be extremely useful. OP would have to clarify, just throwing another option in there.

  10. #10
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Yes, I agree. If anything where historical information may be useful, it is best to keep it.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-22-2014, 06:32 AM
  2. Check For Records From Date Every 7 Days
    By burrina in forum Forms
    Replies: 18
    Last Post: 02-10-2013, 03:46 PM
  3. Replies: 4
    Last Post: 11-10-2011, 03:16 PM
  4. Replies: 2
    Last Post: 10-08-2011, 06:33 PM
  5. Replies: 2
    Last Post: 04-27-2010, 01:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums