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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
| Option Compare Database
Option Explicit
Public strRepertoireDorsale As String
Public strRepertoireImages As String
Dim nbTbl As Long
Dim idx As Long
Dim dbs As DAO.Database
Dim TblDef As DAO.TableDef
Function fCheckLinks()
'--------------------------------------------------------------------------------------------
' Projet : Environnement application
' Appel : Macro ==> AutoExec
' Auteur : Pierre (3stone) - http://www.3stone.be/access/
' Version : 1.0
' Révision : -
' Commentaires : Permet de vérifier la connexion aux tables attachées
' Lien : http://www.3stone.be/access/articles.php?lng=fr&pg=28
'--------------------------------------------------------------------------------------------
Dim rst As DAO.Recordset
Set dbs = CurrentDb()
On Error Resume Next
nbTbl = dbs.TableDefs.Count
For idx = 0 To nbTbl - 1
Set TblDef = dbs.TableDefs(idx)
If TblDef.Attributes = dbAttachedTable Then
Set rst = dbs.OpenRecordset(TblDef.Name)
End If
Next idx
If Err <> 0 Then
fRefreshLinks
End If
rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing
End Function
Sub fRefreshLinks()
'--------------------------------------------------------------------------------------------
' Projet : Environnement application
' Appel : Function ==> fCheckLinks
' Auteur : Pierre (3stone) - http://www.3stone.be/access/
' Version : 1.0
' Révision : -
' Commentaires : Permet de rétablir la connexion aux tables attachées
' Lien : http://www.3stone.be/access/articles.php?lng=fr&pg=28
'--------------------------------------------------------------------------------------------
Dim newpath As String
On Error Resume Next
'Ouverture de la boîte de dialogue Ouvrir fichier ==> Module modDialogbox
newpath = OuvrirFichier(Application.hWndAccessApp, "Choisir l'emplacement des données !", 1, "Fichier Access", "mdb", "C:")
For idx = 0 To nbTbl - 1
Set TblDef = dbs.TableDefs(idx)
If TblDef.Connect <> "" Then
TblDef.Connect = ";DATABASE=" & newpath
TblDef.RefreshLink
End If
Next idx
If Err = 0 Then
MsgBox "Les liaisons ont été rétablies!", vbInformation + vbOKOnly, "Connection réussie"
Exit Sub
Else
If MsgBox("Les données n'ont pas été trouvées " _
& "dans la base sélectionnée ! Voulez-vous essayer à nouveau ?", _
vbExclamation + vbYesNo, "Connection non-réussie") = vbNo Then
dbs.Close
Set dbs = Nothing
Set TblDef = Nothing
MsgBox "Fermeture de l'application !", vbCritical + vbOKOnly, "Fermeture"
Application.Quit
Else
dbs.Close
Set dbs = Nothing
Set TblDef = Nothing
Call fCheckLinks
End If
End If
End Sub
Function InfosDorsale()
'--------------------------------------------------------------------------------------------
' Projet : Environnement application
' Appel : Macro ==> AutoExec
' Auteur :
' Version : 1.0
' Révision : -
' Commentaires : Permet de connaître le chemin complet de la base de données dorsale et le
' : répertoire dans lequel elle est installée, ainsi que le répertoire des
' photos
' Lien : -
'--------------------------------------------------------------------------------------------
On Error Resume Next
Dim strCheminDorsale As String
'Recherche le nom du répertoire dans lequel est installée la base de données dorsale, ainsi que le nom du fichier
strCheminDorsale = CurrentDb.TableDefs("Les protections").Connect
strCheminDorsale = Right(strCheminDorsale, Len(strCheminDorsale) - InStr(1, strCheminDorsale, "DATABASE=") - 8)
'Recherche le nom du répertoire et des sous-répertoires
If Right(strCheminDorsale, 1) = "\" Then
strRepertoireDorsale = strCheminDorsale
Else
strRepertoireDorsale = Left(strCheminDorsale, InStrRev(strCheminDorsale, "\"))
End If
'Répertoire d'installation de la dorsale
strRepertoireDorsale = strRepertoireDorsale
'Répertoire d'installation des photos
strRepertoireImages = strRepertoireDorsale & "Images\"
End Function |
Partager