Buongiorno a tutti.
Con la sottoelencata routine (abbinata ad un pulsante di comando) effettuo giornalmente la copia di Backup di un database di Access (monoutenza) e salvo il file in una cartella apposita.
Public Function BackupOnOpen()
' *** CHANGE THE FOLLOWING LINE TO MATCH YOUR BACKUP DESTINATION
' Ensure you have a \ on the end of the pathname.
Const BACKUP_PATH = "C:\Accessi"
On Error GoTo BackupOnOpen_Err
If DCount("BackupDate", "tblBackupDetails", "BackupDate = date()") <> 0 Then
Exit Function
End If
Dim strSourcePath As String
Dim strSourceFile As String
Dim strBackupFile As String
strSourcePath = GetFileName(CurrentDb.Name, False) ' false means we want pathname
strSourceFile = GetFileName(CurrentDb.Name, True) ' true means we want filename
strBackupFile = "BackupDB-" & Format(Date, "yyyy-mm-dd") _
& "_" & Format(Time, "hh.mm.ss") & "-" & strSourceFile
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile strSourcePath & strSourceFile, BACKUP_PATH & strBackupFile, True
MsgBox "Backup Completato!"
Set fso = Nothing
DoCmd.SetWarnings False
Dim SQL As String
SQL = "INSERT INTO tblBackupDetails " _
& "(BackupDate, ComputerName, BackupFolder, Filename) " _
& "VALUES ('" & Date & "', '" & Environ("COMPUTERNAME") _
& "', '" & BACKUP_PATH & "', '" & strBackupFile & "');"
DoCmd.RunSQL SQL
SQL = "DELETE * FROM tblBackupDetails WHERE BackupDate < date() - 30;"
DoCmd.RunSQL SQL
DoCmd.SetWarnings True
BackupOnOpen_Exit:
Exit Function
BackupOnOpen_Err:
MsgBox Err.Description, , "BackupOnOpen()"
Resume BackupOnOpen_Exit
End Function
Chiedo il vostro aiuto per poter creare ( all'interno delle stessa routine oppure con un'altra a parte) una sub che elimini i files più vecchi di 30 gg. nell'apposita cartella, dove sono contenuti i files di Backup.
Ringrazio chi mi aiuta in questo.
Ciao Nicola.