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?
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 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
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.
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 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.
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.
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.