I need to delete an old table in a backend DB and then add a new table by the same name. Does the links need to be "refreshed" after doing this?
My problem is to get to the backend DB (c:\pisprg\Pisd ataV2.accdb) and use DeleteTable "Fis_itemsT " in Line 3
I use the following code.
I will call the following code to refresh links afterwards
Any suggestions and am i on the right track?
My problem is to get to the backend DB (c:\pisprg\Pisd ataV2.accdb) and use DeleteTable "Fis_itemsT " in Line 3
I use the following code.
Code:
Dim strMsg As String DoCmd.SetWarnings False DeleteTable "Fis_itemsT" 'i add this same table from the FE DB again after deletion in BE. DoCmd.TransferDatabase acExport, "Microsoft Access", "c:\pisprg\PisdataV2.accdb", acTable, "Fis_ItemsT1", "Fis_ItemsT", False DoCmd.SetWarnings True 'I refresh links now strMsg = RefreshTableLinks() If Len(strMsg & "") = 0 Then Debug.Print "All Tables were successfully relinked." Else MsgBox strMsg, vbCritical End If MsgBox "Update completed succesfully"
Code:
Dim db As DAO.Database Dim tdf As DAO.TableDef Dim strCon As String Dim strBackEnd As String Dim strMsg As String Dim intErrorCount As Integer Set db = CurrentDb For Each tdf In db.TableDefs If Left$(tdf.Connect, 10) = ";DATABASE=" Then strCon = Nz(tdf.Connect, "") strBackEnd = Right$(strCon, (Len(strCon) - (InStrRev(strCon, "\") - 1))) If Len(strBackEnd & "") > 0 Then Set tdf = db.TableDefs(tdf.Name) tdf.Connect = ";DATABASE=" & CurrentProject.Path & strBackEnd tdf.RefreshLink Else intErrorCount = intErrorCount + 1 strMsg = strMsg & "Error getting back-end database name." & vbNewLine strMsg = strMsg & "Table Name: " & tdf.Name & vbNewLine strMsg = strMsg & "Connect = " & strCon & vbNewLine End If End If Next tdf ExitHere: On Error Resume Next If intErrorCount > 0 Then strMsg = "There were errors refreshing the table links: " _ & vbNewLine & strMsg & "In Procedure RefreshTableLinks" RefreshTableLinks = strMsg End If Set tdf = Nothing Set db = Nothing Exit Function
Comment