Ma si ovviamente non è ISTANTANEO... dipende anche dalla rete.
Si tratta di CREARE un oggetto Tabledef in Locale, assegnare il Nome e la proprietà Connect e fare l'append alla collection...!
Carico nel rs l'elenco che leggo dal SERVER e ciclo, quindi di fatto è un lavoro in LOCALE in MEMORIA, deve essere un FULMINE.
Ho provato a guardare con un piccolo DB che ho ascopo di sicurezza.
Scenario tutto Access sia FE-BE.
IL BE sono 89 Tabelle, di cui 2 non le Relinko in quanto sono diservizio.
1° Elenco Tabelle da LINKARE
2° VERSION_CHECK
Queste 2 Tabelle contengono pochi Records.
Le altre 87 vengono LINKATE
La dimensione del BE è di poco più di 200MB, non è un fenomeno come casistica ma nemmeno il DB delle ricette di casa...
Il FE effettua il RELINK delle Tabelle in 5 secondi.
Il DeleteLink impiega leggermente di più, 9s, ma si deve chiudere tutto....
Fai attenzione nel tuo CODICE, chenon conosco, a come effettui il RELINK.
Se utilizzi ad esempio il DoCmd.TransferDatabase, per linkare è ovvio che possa impiegare molto, in quanto questo metodo, ha una particolarità, va ad aggiornare la NAVIGATION PANE, quella laterale, e se lo usi ogni volta, ad ogni LINK aggiorni... e perdi un sacco di tempo.
Agendo invece sulla COLLECTION TABLEDEFS, non aggiorni nulla dell'interfaccia grafica, ed infatti non vedrai le LINKED TABLE finchè non premi F5...
Ma io la NavigationPane la rimuovo, quindi non mi serve.
Stessa cosa vale peril DELETE, se usi il DELETEOBJECT...
Ti posto il Codice pari pari che ho scritto per il RELINK nella SplashForm.
Devi avere una Tabella nel BE[_LKTBL] che io uso per leggere l'elenco... fai anche attenzione che il tutto avvienesempre con un RECORDSET aperto sul BE, quindi con una Connection nel POOL già aperta... e non la deve ricreare tutte le volte.
Se fai qualche prova in confronto con il tuo sistema magari poi dai riscontro, anche per capire se questo approccio è utile.
Option Compare Database
Option Explicit
Private Const sRemoteBE = "\\PercorsoReteRemoto\BE.accdb"
Private Const sRemoteTBL = "_LKTBL"
Private Sub Form_Load()
If DeleteLinkedTable(sRemoteBE) Then
Call ReLinkTable(sRemoteBE)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call DeleteLinkedTable(sRemoteBE)
End Sub
Function DeleteLinkedTable(Optional RemoteBE, Optional Password) As Boolean
On Error GoTo ERR_Handler
Const cObjNotExist = 7874
Const cTableNotExist = 3265
Dim db As DAO.Database
Dim dbL As DAO.Database
Dim rs As DAO.Recordset
Dim strPWD As String
If IsMissing(RemoteBE) Then Err.Raise "10000", "RelinkTable", "BackEnd parameter to Relink Function is missing...!"
If Not fileExists(CStr(RemoteBE)) Then Err.Raise "10001", "RelinkTable", "BackEnd not exist...!"
If Not IsMissing(Password) Then strPWD = ";PWD=" & Password
Set dbL = CurrentDb()
Set db = OpenDatabase(RemoteBE)
Set rs = db.OpenRecordset(sRemoteTBL, dbOpenSnapshot, dbReadOnly)
If Not rs.EOF Then
rs.MoveFirst
Do Until rs.EOF
dbL.TableDefs.Delete rs!tablename
DoEvents
rs.MoveNext
Loop
DBEngine(0)(0).TableDefs.Refresh
End If
DeleteLinkedTable = True
Exit_Here:
On Error Resume Next
rs.Close
db.Close
Set db = Nothing
Set rs = Nothing
Exit Function
ERR_Handler:
Select Case Err.Number
Case cObjNotExist, cTableNotExist: Resume Next
Case Else: MsgBox Err.Number & vbNewLine & Err.Description
End Select
Resume Exit_Here
End Function
Function ReLinkTable(Optional RemoteBE, Optional Password) As Boolean
On Error GoTo ERR_Handler
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim rs As DAO.Recordset
Dim strPWD As String
If IsMissing(RemoteBE) Then Err.Raise "10000", "RelinkTable", "BackEnd parameter to Relink Function is missing...!"
If Not fileExists(CStr(RemoteBE)) Then Err.Raise "10001", "RelinkTable", "BackEnd not exist...!"
If Not IsMissing(Password) Then strPWD = ";PWD=" & Password
Set db = OpenDatabase(RemoteBE)
Set rs = db.OpenRecordset(sRemoteTBL, dbOpenSnapshot, dbReadOnly)
If Not rs.EOF Then
rs.MoveFirst
Do Until rs.EOF
With DBEngine(0)(0)
Set tdf = .CreateTableDef(rs!tablename)
tdf.Connect = ";Database=" & RemoteBE & strPWD
tdf.SourceTableName = rs!tablename
.TableDefs.Append tdf
End With
DoEvents
rs.MoveNext
Loop
DBEngine(0)(0).TableDefs.Refresh
End If
ReLinkTable = True
Exit_Here:
On Error Resume Next
rs.Close
db.Close
Set db = Nothing
Set rs = Nothing
Set tdf = Nothing
Exit Function
ERR_Handler:
Select Case Err.Number
Case Else: MsgBox Err.Number & vbNewLine & Err.Description
End Select
Resume Exit_Here
End Function
Function fileExists(s_fileName As String) As Boolean
Dim obj_fso As Object
Set obj_fso = CreateObject("Scripting.FileSystemObject")
fileExists = obj_fso.fileExists(s_fileName)
End Function
Saluti
@Alex