I've a form button, when click it'll first check if the target backend tables already linked. If not, it'll link to those tables.
I made a function to do this task
This function works if there's no linked table. But it always return False even linked tables exist.
Then I found that the "tdf.Name" is not returning the real table name. It return something like "~TMPCLP52921". That's why the function never return True.
This make the VBA code try to link the table again. And cause error 3012 - Object 'table-name' already exists
I made a function to do this task
Code:
Function ChkLinkTbl(tableName As String) As Boolean
Dim tdf As DAO.TableDef
For Each tdf In CurrentDb.TableDefs
If tdf.Name = tableName Then
ChkLinkTbl = True
Else
ChkLinkTbl = False
Set tdf = Nothing
Exit Function
End If
Next
Set tdf = Nothing
End Function
Then I found that the "tdf.Name" is not returning the real table name. It return something like "~TMPCLP52921". That's why the function never return True.
This make the VBA code try to link the table again. And cause error 3012 - Object 'table-name' already exists