Bonjour à vous.
Si comme moi vous êtes confronté à une base liée qui gonfle comme un ballon, ci-dessous du code pour compacter la BD liée de façon ultra simple et une petite classe de service.
Mon programme suppose qu'au moins une table liée est connue.
J'appelle CompacterBDLiee au moment de la fermeture de mon formulaire menu ce qui correspond normalement à la sortie de mon application
Ci-dessous le module de classe clsInfoFichier
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 Public Sub CompacterBDLiee() 'Compacte la BD liée si elle n'est pas utilisée. Dim db As DAO.Database: Set db = CurrentDb Dim dbLiee As New clsInfoFichier: dbLiee.Chemin_Nom_Extention = Mid(CurrentDb.TableDefs("tblBaseParam").Connect, Len(";DATABASE=") + 1) 'Mettre ici le nom de votre table. Dim ficLie As New clsInfoFichier ficLie.Chemin_Nom_Extention = dbLiee.Chemin_Nom_Extention ficLie.Extention = "l" & dbLiee.Extention If Dir(ficLie.Chemin_Nom_Extention) = "" Then 'Crée une version compactée de la BD Shell "MSACCESS.EXE """ & dbLiee.Chemin_Nom_Extention & """/Compact" Else 'La BD est utilisée, on ne peut pas la compacter. End If Set ficLie = Nothing Set dbLiee = Nothing db.Close: Set db = Nothing End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Option Compare Database Option Explicit Public Chemin As String 'Sans \ à la fin Public Nom As String Public Extention As String Public Property Let Chemin_Nom_Extention(prmChemin_Nom_Extention As String) 'Découpe un nom avec l'extention en ses morceaux Dim positionSlash As Long: positionSlash = InStrRev(prmChemin_Nom_Extention, "\") If positionSlash <> 0 Then Me.Chemin = Left(prmChemin_Nom_Extention, positionSlash - 1) Me.Nom_Extention = Mid(prmChemin_Nom_Extention, positionSlash + 1) Else 'Il n'y a de chemin Me.Chemin = "" Me.Nom_Extention = prmChemin_Nom_Extention End If End Property Public Property Get Chemin_Nom_Extention() As String Chemin_Nom_Extention = Chemin & "\" & Nom & "." & Extention End Property Public Property Let Nom_Extention(prmChemin_Nom_Extention As String) 'Découpe un nom avec l'extention en ses morceaux Dim positionPoint As Long: positionPoint = InStrRev(prmChemin_Nom_Extention, ".") If positionPoint <> 0 Then Nom = Left(prmChemin_Nom_Extention, positionPoint - 1) Extention = Mid(prmChemin_Nom_Extention, positionPoint + 1) Else 'Il n'y a pas d'extention Nom = prmChemin_Nom_Extention Extention = "" End If End Property Public Property Get Nom_Extention() As String Nom_Extention = Nom & "." & Extention End Property
Partager