Per la data ed il nome puoi usare una form, ma perché ti devi complicare la vita? Non puoi usare i valori di sistema? Questo è il mio codice, sicuramente lo si potrà migliorare, ma per me funziona e quindi non perdo tempo a cercare "el fret per el lèt" come
si diceva dalle mie parti...
Public Sub BackupBd()
On Error GoTo BackupBd_Err
DoCmd.Hourglass True
Dim fs, f As Object
Dim wNewFile As String
Dim wOldFile As String
Dim wBckFile As String
'Copie de la BD
Set fs = CreateObject("Scripting.FileSystemObject")
'Backup de l'application
wNewFile = CurrentProject.Path & "" & "Temp_" & CurrentProject.Name
wOldFile = CurrentProject.Path & "" & CurrentProject.Name
wBckFile = CurrentProject.Path & "\Backup" & "Backup_" & Date & "_" & Time & "_" & CurrentProject.Name
fs.CopyFile wOldFile, wNewFile
' Compactage
Application.CompactRepair LogFile:=True, SourceFile:=wNewFile, DestinationFile:=wBckFile
Kill (wNewFile)
GoTo NoBackendAccess (questa parte la saltavo quando avevo il backend su SQL Server. Naturalmente BE e FE devono essere nella stessa directory ed i nomi devono essere standard Pippo.accdb e Pippo_data.accdb)
'Backup des données
wNewFile = CurrentProject.Path & "" & "Temp_" & Left(CurrentProject.Name, Len(CurrentProject.Name) - 6) & "_data.accdb"
wOldFile = CurrentProject.Path & "" & Left(CurrentProject.Name, Len(CurrentProject.Name) - 6) & "_data.accdb"
wBckFile = CurrentProject.Path & "\Backup" & "Backup_" & Date & "_" & Time & "_" & Left(CurrentProject.Name, Len(CurrentProject.Name) - 6) & "_data.accdb"
fs.CopyFile wOldFile, wNewFile
' Compactage
Application.CompactRepair LogFile:=True, SourceFile:=wNewFile, DestinationFile:=wBckFile
Kill (wNewFile)
NoBackendAccess:
gMsg = "***** Backup terminé *****"
MsgBox gMsg, vbExclamation, Application.Name
BackupBd_Exit:
DoCmd.Hourglass False
Exit Sub
BackupBd_Err:
MsgErr Err.Number, Err.Description, "mMain", "BackupBd", Application.Name, vbCritical, "Erreur pendant le backup"
GoTo BackupBd_Exit
End Sub