Hello,
I am attempting to write a procedure that will loop through a directory
of CSV files, linking each of them to a database. I have tested the
following code for XLS files, and it works fine, but receive errors
when I change it to link CSVs.
Sub mcrAllPermut_LinkExternalTables()
Set db = CurrentDb
strDir = "C:\"
strTemp = Dir(strDir & "*.csv*")
Do While Len(strTemp)
strPath = strDir & strTemp
Set tdfLink = db.CreateTableDef(Left(strTemp, 8))
tdfLink.SourceTableName = Left(strTemp, 8)
tdfLink.Connect = "Text;DATABASE=" & strPath
db.TableDefs.Append tdfLink
strTemp = Dir$()
Loop
End Sub
I receive Run-time error '3044': 'C;\<filename>.csv' is not a valid
path.
I have also attempted to manually link one file, then change the
..Connect of that linked table, then .RefreshLink, then .CopyObject to
complete this task, but receive Run-time error '3170': Could not find
installable ISAM.
Here's the code:
Set db = CurrentDb
strDir = "C:\"
strTemp = Dir(strDir & "*.csv*")
Do While Len(strTemp)
'CSV is the name of the table that I linked manually to a .csv file in
the Directory
db.TableDefs!CSV.Connect = strTemp
db.TableDefs!CSV.RefreshLink
DoCmd.CopyObject , Left(strTemp, 8), acTable, "CSV"
Debug.Print strTemp
strTemp = Dir$()
Loop
Your help would be greatly appreciated!
Ben.