'---------------------------------------------------------------------------------------
' Procedure : relnk
' Author    : mellon
' Date      : 13-Mar-2017
' Purpose   : This routine links a known .txt file as a named table in this database.
'  It deletes the existing link before doing the actual re-link. If you don't delete
'the existing link to the table, Access creates a new link table with old table name
'and incremental suffix.
'---------------------------------------------------------------------------------------
'
Sub relnk()
    Dim db As DAO.Database
    Dim tbd As DAO.TableDef
10    On Error GoTo relnk_Error
20    Dim sfilename As String: sfilename = "Filelist.txt"
30    Dim sSpec As String: sSpec = "MyLatestJpgs Link Specification"
40    Dim sTbl As String: sTbl = "MyLatestJpgs"
50    Set db = CurrentDb
60    For Each tbd In db.TableDefs
70      If tbd.Name = sTbl Then
80          db.TableDefs.Delete sTbl
90          Debug.Print Now & " -Link to Table (" & sTbl & ") was deleted  "
100     Else
110     End If
120   Next tbd
130   DoCmd.TransferText acLinkFixed, sSpec, sTbl, sfilename, True
140   Debug.Print Now & " -Table(" & sTbl & ") was relinked to file (" & sfilename & ") "
150   On Error GoTo 0
160   Exit Sub
relnk_Error:
170   MsgBox "Error " & Err.Number & " in line " & Erl & " (" & Err.Description & ") in procedure relnk of Module ModuJED"
End Sub