I am using the below code which usually works. But I am trying to import over 100 CSV file and getting an error
The error:
Run-Time '3125' - FILENAME is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
My code Below:
Sub imports()
Const strPath As String = "J:\Centsupp\Risk Management\Debts Reporting (MD)\Adhoc\06 - Daves Work\Useful Tools\Compile Data\All Files\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
'Loop through the folder & build file list
strFile = Dir(strPath & "*.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"
Exit Sub
End If
'cycle through the list of files & import to Access
'creating a new table called MyTable
For intFile = 1 To UBound(strFileList)
DoCmd.TransferText acImportDelimi, , "addresspoint", strPath & strFileList(intFile)
'Check out the TransferSpreadsheet options in the Access
'Visual Basic Help file for a full description & list of
'optional settings
Next
MsgBox UBound(strFileList) & " Files were Imported"
End Sub