Public Function CompactAndRepairDB()
Dim strDBName As String
Dim strBackupPath As String
' Get the name of the current database
strDBName = CurrentDb.Name
' Set the path for the backup file to the user's desktop
strBackupPath = Environ("USERPROFILE") & "\Desktop\" & Format(Date, "yyyy-mm-dd") & " " & Format(Time, "hh-mm-ss") & " backup.accdb"
' Compact and repair the database
Application.CompactRepair strDBName, strBackupPath
' Display a message when the process is complete
MsgBox "Baza de date a fost compactata si reparata" & vbNewLine & vbNewLine & _
"O copie de rezerva a fost plasata pe Desktop." & vbNewLine & vbNewLine & _
"Puteti sterge copia dupa ce va asigurati ca baza de date este functionala.", vbInformation, ""
End Function