I know this thread is resolved, but this information may help anyone else attempting a similar set up.
I'm linking to a SQL Server database from Access 365 and found this article
Create DSN-less connection to SQL for linked table - Office | Microsoft Learn[
^]
I've reproduced my interpretation of that code here
Public Sub Reconnect()
Dim errs As Integer: errs = 0
ReDim errTables(errs) As String
Dim tables(4) As String
tables(0) = "table1"
tables(1) = "table2"
tables(2) = "table3"
tables(3) = "table4"
Dim i As Integer
For i = 0 To UBound(tables)
Debug.Print "Linking " & tables(i)
If Not AttachDSNLessTable(removeSchemaFromTable(tables(i)), tables(i), dbServer, dbName, dbLogin, dbPass) Then
logTableInError errs, errTables(), tables(i)
End If
Next
If errs > 0 Then
Dim s As String
s = ""
For i = 0 To UBound(errTables)
If Len(errTables(i)) > 0 Then
s = s & errTables(i) & vbCrLf
End If
Next
If Len(LTrim$(RTrim$(s))) > 0 Then
MsgBox "Unable to link the following tables: " & vbCrLf & s
End If
Else
MsgBox "All tables relinked"
End If
End Sub
Private Function removeSchemaFromTable(tablename As String) As String
Dim i As Integer
i = InStr(tablename, ".")
If i = 0 Then
removeSchemaFromTable = tablename
Else
removeSchemaFromTable = Mid$(tablename, i + 1)
End If
End Function
Private Sub logTableInError(ByRef errs As Integer, ByRef errTables() As String, ByVal tablename As String)
ReDim Preserve errTables(errs)
errTables(errs) = tablename
errs = errs + 1
End Sub
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String) As Boolean
On Error GoTo AttachDSNLessTable_Err
Dim td As TableDef
Dim stConnect As String
For Each td In CurrentDb.TableDefs
If td.Name = stLocalTableName Then
CurrentDb.TableDefs.Delete stLocalTableName
End If
Next
If Len(stUsername) = 0 Then
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes"
Else
stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword
End If
Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect)
CurrentDb.TableDefs.Append td
AttachDSNLessTable = True
Exit Function
AttachDSNLessTable_Err:
AttachDSNLessTable = False
End Function
Public Function KeepConn()
On Error GoTo 0
Form_KeepConnectionOpen.Visible = False
End Function
The variables dbServer, dbName, and dbLogin are stored as Consts at the head of the module and dbPass is stored on a table with a Password mask on it's only field. Not completely secure but better than nothing. The VBA project is also locked for viewing.
One interesting feature is the form that is kept open in the background, not visible, to stop the connections from timing out.