Reputation: 317
I'm trying to use the code below to import multiple csvs into one table. For some reason it imports all csvs but creates a separate table for each instead of importing into the UKR table.
I'm using Access 2016 and UKR is a blank table with no field names or data.
Can anyone see what the issue is?
Thanks
Option Compare Database
Option Explicit
Function DoImport()
Dim strPathFile As String
Dim strFile As String
Dim strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
blnHasFieldNames = True
strPath = "C:\UKR\"
strTable = "UKR"
strFile = Dir(strPath & "*.csv")
Do While Len(strFile) > 0
strTable = Left(strFile, Len(strFile) - 4)
strPathFile = strPath & strFile
DoCmd.TransferText acImportDelim, , strTable, strPathFile, blnHasFieldNames
strFile = Dir()
Loop
MsgBox "done"
End Function
Upvotes: 1
Views: 42
Reputation: 21370
Because code is resetting the destination table within the loop. Remove line
strTable = Left(strFile, Len(strFile) - 4)
Upvotes: 1