Results 1 to 6 of 6
  1. #1
    dhen21 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2018
    Posts
    2

    Deleting year record in Access

    Hi all,

    Need help to delete records of previous years via VBA code where input from user is needed (to input the year).
    I have my Date table that has (mm-dd-yyyy hh:mm:ss) format.



    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    you don't need vba, make a query:
    delete * from table where year([field]) = [Enter Year to Delete]"

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,822
    This practice presents some danger if not accounted for, such as deleting from years that should not be, simply over a keyboard typo. Archiving is a method that you might want to consider as deleting records in a repeated fashion isn't usually done. At least that's my perspective.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    rawlstonb is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Nov 2018
    Posts
    55
    .... IRS Audit?

  5. #5
    dhen21 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2018
    Posts
    2
    Hi

    Thanks for your feedback, we are archiving each year in the Excel File. The purpose is to get rid of the archived(per year) data.
    Btw, just also interested in archiving method, can you advise me on how to do.

    Thanks

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,822
    Most common (I think) is an ArchivedDate field or some such name. I use camel case names so not Archived_Date as I'm too lazy to type underscores, and NEVER a space in between. But I digress.

    To archive the record, your form/query writes Date or Now (both are built in functions) to a record. Subsequent queries can therefore show records that are current (... WHERE ArchivedDate Is Null) or have been archived (...WHERE ArchivedDate Is Not Null) or > than some date or between two dates, if you prefer. You could use a checkbox field, but a date field is more informative in that you can know when it was archived. You also cannot search a checkbox field with operators such as <, >, <>, BETWEEN, etc. dates.

    That is all on the understanding that this involves Access tables, as I'm not sure how your Excel reference comes into play.

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

Similar Threads

  1. Deleting a record and all associated information
    By ExponentiaI in forum Queries
    Replies: 3
    Last Post: 03-17-2017, 10:16 AM
  2. Deleting current record using VBA
    By Kivan in forum Programming
    Replies: 3
    Last Post: 08-07-2012, 11:31 AM
  3. Deleting a record
    By alexc333 in forum Access
    Replies: 7
    Last Post: 07-26-2011, 10:43 AM
  4. Problem deleting record
    By Vikki in forum Access
    Replies: 8
    Last Post: 02-26-2010, 11:07 AM
  5. Deleting Record Contents, not complete record...
    By Charles Waters in forum Access
    Replies: 2
    Last Post: 06-24-2008, 12:00 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