我試圖查找如果後端數據庫位於正確 後,我跑我的代碼,如果它與返回錯誤,一切都很好,但是當涉及沒有錯誤返回,因此它使整個應用程序停止。 以下是我的VBA代碼:MS Access數據庫VBA後端檢查,使項目停止
Function CheckLinkedDb()
cDBPath = Application.CurrentProject.Path
Set db = CurrentDb
Dim Relink_Tables
Dim rsCheckLink As Recordset
Relink_Tables = False
For Each tdf In db.TableDefs
If Len(tdf.Connect) > 0 Then
''Linked table - test link is current
DoCmd.SetWarnings False
On Error Resume Next 'Do not stop script on error
Set rsCheckLink = db.OpenRecordset(tdf.Name) ' OPEN TABLE
DoCmd.Echo False, "Checking link for table " & tdf.Name
DoCmd.SetWarnings True
If Err Then ' COULD NOT OPEN TABLE
Relink_Tables = True
'GoTo Relink_Tables ' RECONNECT TO APPROPIATE DATABASE
Else
rsCheckLink.Close ' CLOSE TABLE THAT DID OPEN
Set rsCheckLink = Nothing
End If
End If
Next
If Relink_Tables = True Then
goto RelinkT....
End Function
你有'DoCmd.Echo TRUE'某處後面的代碼? – HansUp