I have some linked Txt and EXL files, and some code to refresh link, it works fine on the txt files but fails with the xls file.
gives error 3051 and says it is already opened exclusively by aniother user!
this is a stand alone envioronmnet, and it links fine if i us the manulal Linked Table Manager.
Code shown Below
-----------------------
Private Sub optLink_Click()
Dim strFileName$
Dim tdf As TableDef
Dim strConnect As String
For Each tdf In CurrentDb.TableDefs
If tdf.SourceTableName <> "" Then
Debug.Print tdf.SourceTableName
strFileName = GetPath & "\RawData" '\" & tdf.SourceTableName
If tdf.SourceTableName = "INVMONTHMIC.txt" Then GoTo exit_next 'error they still appear in database god know why!
If tdf.SourceTableName = "INVMONTHBHI.txt" Then GoTo exit_next
If tdf.SourceTableName = "CELLPATH.csv" Then GoTo exit_next
strConnect = Mid(tdf.Connect, 1, InStr(tdf.Connect, "Database=") + 8) & strFileName
' tdf.Connect = strFileName
tdf.Connect = strConnect
tdf.RefreshLink
End If
exit_next:
Next
MsgBox "all data has been relinked"
Me.optLink = Null
End Sub
-------------------------------------
any help much aprreciated
Toby
gives error 3051 and says it is already opened exclusively by aniother user!
this is a stand alone envioronmnet, and it links fine if i us the manulal Linked Table Manager.
Code shown Below
-----------------------
Private Sub optLink_Click()
Dim strFileName$
Dim tdf As TableDef
Dim strConnect As String
For Each tdf In CurrentDb.TableDefs
If tdf.SourceTableName <> "" Then
Debug.Print tdf.SourceTableName
strFileName = GetPath & "\RawData" '\" & tdf.SourceTableName
If tdf.SourceTableName = "INVMONTHMIC.txt" Then GoTo exit_next 'error they still appear in database god know why!
If tdf.SourceTableName = "INVMONTHBHI.txt" Then GoTo exit_next
If tdf.SourceTableName = "CELLPATH.csv" Then GoTo exit_next
strConnect = Mid(tdf.Connect, 1, InStr(tdf.Connect, "Database=") + 8) & strFileName
' tdf.Connect = strFileName
tdf.Connect = strConnect
tdf.RefreshLink
End If
exit_next:
Next
MsgBox "all data has been relinked"
Me.optLink = Null
End Sub
-------------------------------------
any help much aprreciated
Toby