Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Button to archive data based on date - how?

Status
Not open for further replies.

scar

Programmer
May 18, 2002
10
GB
I want to have a button on my form which archives records in a table (copies to another table and deletes original) where the date in the record is > 6 months old.
Is it best to use a macro to run a couple of queries, or shall I do this in VBA SQL? Also, how do I calculate '6 months back from current date'?

Many thanks all!
 
you could try putting this into your date field of the query:-

<Date()-180

This will look at everything over 180 days old (which is pretty close)

 
You could use either queries or sql depending on what your needs are and how comfortable you are with either method. If you want to archive all records over 6 months old you could just run an append query to copy those records using criteria offered by Gazer44 to the archive table and then run a delete query to remove records from first table. If other criteria are involved then they will have to be added to query criteria as well. Be sure append and delete queries use same criteria or you will have an inconsistent append/delete. Access Help can give you examples of the two types of queries.
 
Thanks very much. I've got it working in queries with the 180 method. Thanks also for the advice, evalesthy.
 
Scar, use VB instead of macros. As evalesthy stated, you can have either pre-defined queries in your database or you can create the SQL in the VB module.

I think having pre-defined queries will be a bit more efficient in the long run, and you can execute them in your module just by using the docmd.openquery statement.

Public Sub archive_click()
docmd.openquery &quot;append query name here&quot;
docmd.openquery &quot;delete query name here&quot;
End Sub
Maq [americanflag]
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top