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
|
Function RefreshLinks() As Boolean
Dim collTbls As Collection
Dim i As Integer
Dim strTbl As String
Dim dbCurr As Database
Dim dbLink As Database
Dim tdfTables As TableDef
Dim strBeFile As String
Dim collTables As New Collection
Dim tdf As TableDef
Dim strMsg As String
Set dbCurr = CurrentDb
dbCurr.TableDefs.Refresh
For Each tdf In dbCurr.TableDefs
With tdf
If Len(.Connect) > 0 Then
collTables.Add Item:=.Name & .Connect, Key:=.Name
End If
End With
Next
Set collTbls = collTables
' strBeFile = CurrentProject.Path & "\Data\TestData.mdb"
'partie ajoutée (il faut ajouté la référence à Microsoft Office xx.x Library)
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Choix de la base"
.Filters.Clear
.Filters.Add "BD access", "*.mdb, *.accdb"
If .Show = True Then
strBeFile = Trim(.SelectedItems.item(1))
Else
MsgBox "Choix annulé!"
End If
End With
'fin partie ajoutée
Set dbLink = DBEngine(0).OpenDatabase(strBeFile)
For i = collTbls.Count To 1 Step -1
strTbl = Left$(collTbls(i), InStr(1, collTbls(i), ";") - 1)
Set tdfTables = dbCurr.TableDefs(strTbl)
With tdfTables
.Connect = ";Database=" & strBeFile
.RefreshLink
End With
Next
strMsg = "Reinitialisation liaison " & vbNewLine & vbNewLine
strMsg = strMsg & " La mise à jour des liaisons de l' application a été réalisé avec succès." & vbNewLine
MsgBox strMsg, vbInformation, "Liaisons tables"
End Function |
Partager