There were a couple things that resulted in the odd behavior.
First, the linked table had initially used the SQL Server
driver, not the SQL Server Native Client 10.0
one. So, when I refreshed the tables I selected the incorrect one (I knew it wasn't 11.0
, but thought it was 10.0
).
The second issue is that when the Access tables were converted over to SQL Server the datetime fields were setup as datetime2(0) (Access 2010 migration tool was used). Unfortunately the SQL Server
driver doesn't support these.
We want users to authenticate via Windows Authentication (again, legacy app that'll hopefully get moved to the web or a 3rd-party solution one-day), and we know it works this way.
After altering the SQL Server tables to use datetime instead of datetime2, the below code worked just fine:
Option Compare Database
Option Explicit
Function RefreshLinkedTables() As Boolean
Dim db As DAO.Database
Dim tb As DAO.TableDef
Set db = CurrentDb
For Each tb In db.TableDefs
' Skip system files.
If (Mid(tb.Name, 1, 4) <> "MSys" And Mid(tb.Name, 1, 4) <> "~TMP") Then
Debug.Print tb.Name
Debug.Print tb.Connect
If (Mid(tb.Connect, 1, 5) = "ODBC;") Then
'We only need to refresh a single table.
If (tb.Name = "Jobs") Then
tb.Connect = tb.Connect & ""
'Live connection
'tb.Connect = "ODBC;Description=___;DRIVER=SQL Server;SERVER=___;APP=Microsoft Office 2010;DATABASE=___"
'Dev connection
'tb.Connect = "ODBC;Description=___;DRIVER=SQL Server;SERVER=___;APP=Microsoft Office 2010;DATABASE=___"
tb.RefreshLink
End If
'tb.RefreshLink
End If
Debug.Print "=== === ==="
End If
Next
db.TableDefs.Refresh
Set db = Nothing
RefreshLinkedTables = True
Exit Function
End Function
Logic could be cleaned up a bit more, but it works.
Thanks to Gord Thompson for his helpful comments.