所以,我需要一种方法刷新Access数据库中的链接表,这样如果因某种原因Internet断开连接,ODBC在发送查询时不会出错,只需刷新以查看查询可以再次发送。但是,当Internet重新启动时,Access数据库由于某种原因不会重新连接。如果发生这种情况,是否有办法在VBA中刷新链接表?
答案 0 :(得分:1)
.RefreshLink
方法会做你想做的吗?
这里有一个例子:https://msdn.microsoft.com/en-us/library/office/ff198349.aspx
另一个解决方案是重新连接到调用此函数的远程数据库。
Function ConnectODBC(ByVal strDsn As String, ByVal strDatabase As String, ByVal strUserName As String, ByVal strPassword As String)
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim strConnection As String
strConnection = "ODBC;DSN=" & strDsn & ";" & _
"DATABASE=" & strDatabase & ";" & _
"UID=" & strUserName & ";" & _
"PWD=" & strPassword
Set qdf = CurrentDb.CreateQueryDef("")
With qdf
.Connect = strConnection
.SQL = "SELECT 1;"
End With
Set rst = qdf.OpenRecordset(dbOpenSnapshot, dbSQLPassThrough)
ConnectODBC = True
Set rst = Nothing
Set qdf = Nothing
End Function