1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
Option Compare Database
Option Explicit
Private Sub btCopieCompact_Click()
Dim pass As String
If trouveGroupe(CurrentUser) = "Maintenance" Then
pass = InputBox("Veuillez entrer le mot de passe!", "mot de passe")
If Trim(pass) = "sauver" Then
copyAndCompact2
Else
MsgBox "Le mot de passe est erroné!", vbCritical
DoCmd.Close
End If
Else
copyAndCompact
End If
End Sub
Function copyAndCompact()
Dim fichierSysteme As New FileSystemObject
DoCmd.Hourglass True
If fichierSysteme.FileExists("g:\GEG\backup\maintenanceBackup.mdb") = True Then
fichierSysteme.DeleteFile "g:\GEG\backup\maintenanceBackup.mdb", True
End If
If fichierSysteme.FileExists("g:\GEG\backup\maintenance.mdb") = True Then
fichierSysteme.DeleteFile "g:\GEG\backup\maintenance.mdb", True
End If
fichierSysteme.CopyFile "g:\GEG\maintenance.mdb", "g:\GEG\backup\maintenance.mdb", True
If fichierSysteme.FileExists("C:\Program Files\Microsoft Office\Office\MSAccess.exe") Then
Shell "C:\Program Files\Microsoft Office\Office\MSAccess.exe G:\GEG\backup\maintenance /COMPACT"
Else
If fichierSysteme.FileExists("N:\MSOFFICE\OFFICE\MSACCESS.EXE") Then
Shell "N:\MSOFFICE\OFFICE\MSACCESS.EXE G:\GEG\backup\maintenance /COMPACT"
Else
MsgBox "Le compactage a échoué car vous n'avez pas Access d'installé!", vbCritical
End If
End If
DoCmd.Hourglass False
DoCmd.Close
End Function
Function copyAndCompact2()
Dim fichierSysteme As New FileSystemObject
DoCmd.Hourglass True
If fichierSysteme.FileExists("g:\GEG\backup\maintenanceBackup.mdb") = True Then
fichierSysteme.DeleteFile "g:\GEG\backup\maintenanceBackup.mdb", True
End If
If fichierSysteme.FileExists("g:\GEG\backup\maintenance.mdb") = True Then
fichierSysteme.DeleteFile "g:\GEG\backup\maintenance.mdb", True
End If
fichierSysteme.CopyFile "g:\GEG\maintenance.mdb", "g:\GEG\backup\maintenance.mdb", True
DBEngine.CompactDatabase "g:\GEG\backup\maintenance.mdb", "g:\GEG\backup\maintenanceBackup.mdb"
If fichierSysteme.FileExists("g:\GEG\backup\maintenance.mdb") = True Then
fichierSysteme.DeleteFile "g:\GEG\backup\maintenance.mdb", True
End If
DoCmd.Hourglass False
DoCmd.Close
MsgBox "La copie et le compactage de GEG est réussi avec succès!"
End Function |
Partager