I'm creating a code to import a list of csv's into various tables. The code loops through the csv's and tables to import each one a create a table. The code works perfectly but only when I have the csv open. Why do I have to have the csv open? And how do I fix the code so that I do not have to have each csv open? Code is:
Sub ImportData()
Dim filepath(3) As String
Dim tablename(3) As String
filepath(1) = "N:\CompanyA\Model\2018-09-01\Inputs\Tomato.csv"
filepath(2) = "N:\CompanyA\Model\2018-09-01\Inputs\Apple.csv"
filepath(3) = "N:\CompanyA\Model\2018-09-01\Inputs\Pear.csv"
tablename(1) = "8594_Tomato"
tablename(2) = "15692_Apple"
tablename(3) = "10567_Pear"
For i = 1 To 3
DoCmd.TransferSpreadsheet acImport, , tablename(i), filepath(i), True
Next i
End Sub
Thanks :)