Just noticed this morning that when I try to get the connection string from a SQL Server linked table in VBA, it starts with "ODBCDRIVER=" instead of "ODBC;DRIVER=". I am getting the string from a current linked table to use as the connection string for a QueryDef in VBA. The missing semicolon causes the code with the QueryDef to raise error 3305: Invalid connection string in pass-through query.
Here is my function to return the connection string. It was returning a valid connection string previously and (as far as I remember) I hadn't made any changes.
Public Function GetObjectConnectString(ObjectName As String, ObjectType As String) As String
GetObjectConnectString = vbNullString
Dim ConnectString As String
Select Case ObjectType
Case "Table"
ConnectString = db.TableDefs(ObjectName).Connect
Case "Query"
ConnectString = db.QueryDefs(ObjectName).Connect
End Select
GetObjectConnectString = ConnectString
End Function
Is this expected behavior and I just need to handle this response by adding in the semicolon?
Using: Microsoft Access for Microsoft 365 MSO (Version 2312 Build 16.0.17126.20078) 64-bit Microsoft Visual Basic for Applications 7.1 Version 1131
Edit
Here is the db function:
Private my_db As DAO.Database
Public Function db() As DAO.Database
Set db = my_db
ErrEx.Catch 91, 3420 'no longer set
Set my_db = CurrentDb
Resume
End Function
You must have updated your MS Access and you are on version 2312. That is the reason! There is a bug in the update released by Microsoft which messed up the connection string as you noticed. A new update fixing the issue is expected to be released by Microsoft soon. See this link for more info:
https://www.accessforever.org/post/missing-semicolon-in-odbc-connect