Access VBA pass-through query connection string update doesn't work

时间:2016-10-20 19:53:35

标签: ms-access access-vba

Afternoon all,

I have a simple problem that has me stumped. I am trying to change the connection strings for my pass-though queries. My issue is, it seems to work. The connection strings do get updated to the new connection string, however, when I run it, it is clearly using the previous connection string.

Code:

Sub UpdatePassthroughConnecStrings()
    Dim qdf As QueryDef

    For Each qdf In CurrentDb.QueryDefs
        If qdf.Type = dbQSQLPassThrough Then
            qdf.Connect = ConnectString
        End If
    Next qdf

End Sub

Function ConnectString() As String
    Dim strYear As String

    strYear = "LIMS" & Form_frm_Main.Year
    ConnectString = "ODBC;DSN=LIMS;UID=" & strYear & ";PWD=1234;"

End Function

Basically, I am updated the UID portion so I can connect to the correct Oracle db tablespace (it's split by year). When I check the connection strings after the update it is correctly updated but just doesn't connect correctly. Interestingly, this code works in Excel just fine. Any help would be appreciated!

0 个答案:

没有答案