Hello
I need to import large csv files ino a single table everyday. I currently have a piece of code that goes through the folder containing csv files and imports the the data into my access table.
How would i go about filtering each csv file based on the contents in column 1, before importing the filtered contents into access.
The code so far is:
Sub Import_multiple_csv_files()
'Modified from WillR - www.willr.info (December 2004)
Const strPath As String = "C:\Users\data\Desktop\data\" '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, , _
"data", 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
Bookmarks