Delete backup database (1 Viewer)

eMel

Registered User.
Local time
Today, 14:12
Joined
Jun 23, 2014
Messages
62
I have a database that creates a backup database, and places it in a separate folder, when opened. The backup database's name is test_mm/dd. I want the ten day old database to be deleted at the same time. Suggestions?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:12
Joined
Feb 28, 2001
Messages
27,001
If you know the name, VBA has a verb for this... KILL file-spec

If you DON'T know the name, look up the FileSystemObject, which you can use to look at files, search by name, and delete by name once you found what you wanted.

 

Dreamweaver

Well-known member
Local time
Today, 21:12
Joined
Nov 28, 2005
Messages
2,466
I always keep 7 days of my current development project I was thinking of automating the delete but to be honest I didn't want to leave it to code, It's just me on that but i find it simple to open the folder and delete a few files job done in 10 seconds
 

eMel

Registered User.
Local time
Today, 14:12
Joined
Jun 23, 2014
Messages
62
If you know the name, VBA has a verb for this... KILL file-spec

If you DON'T know the name, look up the FileSystemObject, which you can use to look at files, search by name, and delete by name once you found what you wanted.

I know the name. I have several databases that I back up. Once the database back up is ten days old, I want to auto delete. This could be done when the current database is opened.
 

eMel

Registered User.
Local time
Today, 14:12
Joined
Jun 23, 2014
Messages
62
I always keep 7 days of my current development project I was thinking of automating the delete but to be honest I didn't want to leave it to code, It's just me on that but i find it simple to open the folder and delete a few files job done in 10 seconds
I have six databases that I want to do this with. I might also expand this to all Access databases.
 

Isaac

Lifelong Learner
Local time
Today, 14:12
Joined
Mar 14, 2017
Messages
8,738
I know the name. I have several databases that I back up. Once the database back up is ten days old, I want to auto delete. This could be done when the current database is opened.
Then do what the Doc Man said.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:12
Joined
Oct 29, 2018
Messages
21,358
Hi. If the names of your files cannot tell you if they're 10 days old, then you could try using the FileDateTime() function. You would loop through the files and check if it's 10 days old and then Kill it.

 

Dreamweaver

Well-known member
Local time
Today, 21:12
Joined
Nov 28, 2005
Messages
2,466
You could give each file a name that included a formated date and or time of the backup should be quite simple to find then
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 16:12
Joined
Feb 28, 2001
Messages
27,001
The Doc Man didn't suggest a way to do this when the main database is opened, which is my question.

If you want to do this each time the database is opened, you NOW have the problem that you need to see if the file was deleted earlier when you opened the database. Then closed it, went away for lunch, and came back and opened it again. (Or got up for a potty break, or maybe the boss called you to his office for a moment... - surely you do not leave a database open on your desktop if you have to walk away for a moment...?)

IF you have a form that is identified as the database's opening form, you can put something in that form's Form_OnOpen or Form_OnLoad event routine to test for the existence of the file and just delete it. OR have code to disable errors for a moment, kill the file while ignoring errors, and then enable your error handling.

If you DON'T have a designated opening form (or opening macro), you pretty much have a problem because code doesn't run in the database without some predefined context. I.e. Access doesn't run anything unless you tell it to run something, and if you are going to run code, you need to have a "medium" in which that code can run. Such as in the class module of an opening form, or in a RunCode option in an opening macro.
 

Isaac

Lifelong Learner
Local time
Today, 14:12
Joined
Mar 14, 2017
Messages
8,738
The Doc Man didn't suggest a way to do this when the main database is opened, which is my question.
Yes, he did. Use the KILL command. You'll probably need to add in some Date functions to figure out the correct filename, too
 

Users who are viewing this thread

Top Bottom