https://github.com/walter426/VbaUtilities/blob/master/AccessObjUtilities.bas
As it is unable to add a link table directly by "CreateTableDef" method, so it needs to make below function to do so.
'Link Table Through Table Definition
Public Function LinkTblByTdf(Tbl_src_name As String, Tbl_des_name As String, str_conn As String) As String
On Error GoTo Err_LinkTblByTdf
Dim FailedReason As String
DelTable (Tbl_des_name)
With CurrentDb
Dim tdf As TableDef
Set tdf = .CreateTableDef(Tbl_des_name)
tdf.Connect = str_conn
tdf.SourceTableName = Tbl_src_name
.TableDefs.Append tdf
.TableDefs(Tbl_des_name).RefreshLink
End With 'CurrentDb
RefreshDatabaseWindow
Exit_LinkTblByTdf:
LinkTblByTdf = FailedReason
Exit Function
Err_LinkTblByTdf:
FailedReason = Err.Description
Resume Exit_LinkTblByTdf
End Function
Supplement:
My intention to write this function is to link SQLite database through ODBC.
Unfortunately, the MS Access application will be closed after it is linked to some SQLite table sometimes, with an error number, 462, which means "remote server machine not found.".
If the failure occurs, the only thing can do is to open the access application and re-link the table again.
i'm sorry that I did not find any fix or workaround to overcome this bug.
沒有留言:
張貼留言