The most common mistake in this situation is to forget .RefreshLink TableDef, but you already do it. I just tested the following VBA code that switches the linked table named [Products_linked] between two access files: Products_EN.accdb (English) and Products_FR.accdb (French). If I run VBA code and immediately open the linked table, I see that this change has occurred; I do not need to close and reopen the database.
Function ToggleLinkTest() Dim cdb As DAO.Database, tbd As DAO.TableDef Set cdb = CurrentDb Set tbd = cdb.TableDefs("Products_linked") If tbd.Connect Like "*_EN*" Then tbd.Connect = Replace(tbd.Connect, "_EN", "_FR", 1, 1, vbBinaryCompare) Else tbd.Connect = Replace(tbd.Connect, "_FR", "_EN", 1, 1, vbBinaryCompare) End If tbd.RefreshLink Set tbd = Nothing Set cdb = Nothing End Function
I even tested calling this code from an AutoExec macro, and it also works as expected.
One thing you could try would be to call db.TableDefs.Refresh at the end of your procedure to see if that helps.
Edit
The problem was that the database had a “display form” specified in the “Application Settings”, and this form appears to automatically open before the AutoExec macro runs. Moving a function call to re-bind the code to the Form_Load event handler for this "launch form" seems like a likely fix.
source share