I have over 100 CSV files all with the same format and structure. I have imported one of those into a new table in Access but I do not want to have to do this one by one for each CSV!. In a bid to solve this I searched for a piece of code that could handle batch imports.
the run time error I get is run time error 9 'subscript of of range' The culprit is highlighted in the code above.
any ideas what is causing this?
Code:
Private Sub Command3_Click()
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim filename As String
Dim path As String
DoCmd.SetWarnings False
path = "C:\Test\"
'Loop through the folder & build file list
strFile = Dir(path & " * .csv *")
While strFile <> ""
'add files to the list
intFile = intFile + 1
ReDim Preserve strFileList(1 To intFile)
strFileList(intFile) = strFile
strFile = Dir()
Wend
'see if any files were found
If intFile = 0 Then
MsgBox "No files found"
End If
'cycle through the list of files
[B]For intFile = 1 To UBound(strFileList)
[/B]filename = path & strFileList(intFile)
DoCmd.TransferSpreadsheet acImport, codepointimport, MyTable, filename, True
Next intFile
DoCmd.SetWarnings True
End Sub
the run time error I get is run time error 9 'subscript of of range' The culprit is highlighted in the code above.
any ideas what is causing this?