У меня есть несколько файлов CSV в нескольких папках, все в одной главной папке на диске C :.Некоторые файлы обновляются каждый день.Если файл имеет обновление, мне нужно загрузить новые ежедневные данные в таблицу доступа, включая имя файла.Пока что скрипт импортирует все данные из всех файлов CSV.Затем он добавляет имя файла в новую запись.Мне нужно, чтобы имя файла было добавлено ко всем записям.
Любая помощь будет высоко оценена.
Скрипт:
Sub Import_multiple_csv_files ()
Const strPath As String = "C:\text1\" 'Directory Path
Dim strFile As String 'Filename
Dim strFileList() As String 'File Array
Dim intFile As Integer 'File Number
Dim rs As DAO.Recordset
'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, , _
"Test", strPath & strFileList(intFile)
‘add file name to record
Set rs = CurrentDb.OpenRecordset("Test")
rs.AddNew
rs.Fields("Com").Value = Dir(strPath & "*")
rs.Update
rs.Close
Set rs = Nothing
Next
MsgBox UBound(strFileList) & " Files were Imported"
End Sub