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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy and delete tables

Status
Not open for further replies.

Moxy1

Programmer
Aug 29, 2002
75
0
0
US
I'm using Access 2000. I am making a copy of a table before making modifications to it with;

dim varDate as Date
varDate = Now()

docmd.copyobject "", "table" & varDate, acTable, "table"

What I would like to do is have a second part of code that will look at the varDate part of the table name and delete the object if it is 3 months old. Can this be done?

Thanks,
Moxy
 
Moxy,

I would use tableDefs, something like this:
lets assume your tablename is tblX01012004 where 01012004 represents the date

Public Sub DeleteOldTable ()
dim db as databse, Mytable as tabledef, tableName as string

set db = currentDB

For Each Mytable In db.TableDefs
tablename = mytable.Name
'the next line formats the date protion of the tablename and if it is more than 92 days before todays date deletes the table from the tabledefs collection
if format(right(tablename,8),&quot;mmddyyyy&quot;) < (date()- 92) Then
db.TableDefs.Delete tablename
end if
Next Mytable

Set db = Nothing

End Sub

I have not tested the above so it may be a bit buggy, please come back with any problems.

HTH

Rich


Bespoke and off-the-shelf Access solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top