Excel Data Connection Locks Access DB, Prevents Second Connection's Refresh

后端 未结 4 1162
囚心锁ツ
囚心锁ツ 2021-02-09 17:35

I have two data connections to different queries in the same Access DB. The second one always fails (regardless of which I run first).

When I look at the database, I no

4条回答
  •  遥遥无期
    2021-02-09 18:08

    I was faced with another issue regarding data connections, and the solution for it actually ended up fixing this long-standing issue as well!

    My guess is that the secret lies in "MaintainConnection = False":

    Dim i As Integer
    Dim awc As WorkbookConnection
    Dim c As OLEDBConnection
    
    For i = 0 to ActiveWorkbook.Connections.Count
        Set awc = ActiveWorkbook.Connections.Item(i)
        Set c = awc.OLEDBConnection
        c.EnableRefresh = True
        c.BackgroundQuery = False
        c.Reconnect
        c.Refresh
        c.MaintainConnection = False
    Next i
    

提交回复
热议问题