Hello everyone
I am new to this site and definitely not a programmer but I have a problem with importing multiple csv files and would appreciate any help with my problem
I have managed to get this code to bring in the files but now I need it to populate a column that is empty with the filename of the imported csv file
I have thousands of these files to import into a single table but I need to label each record with the source filename
This is what I have that works for importing but I have no clue as to how to populate the records with the name.
Any help with this would be much appreciated
Tommy
Sub Import_Counts_csv_files()
Const strPath As String = "H:\My Documents\Gatwick\Database\counts\test" '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
For intFile = 1 To UBound(strFileList)
DoCmd.TransferText acImportDelimi, , _
"counts", strPath & strFileList(intFile), HasFieldNames:=True
Next
MsgBox UBound(strFileList) & " Files were Imported"
End Sub
Thanks again in anticipation
I am new to this site and definitely not a programmer but I have a problem with importing multiple csv files and would appreciate any help with my problem
I have managed to get this code to bring in the files but now I need it to populate a column that is empty with the filename of the imported csv file
I have thousands of these files to import into a single table but I need to label each record with the source filename
This is what I have that works for importing but I have no clue as to how to populate the records with the name.
Any help with this would be much appreciated
Tommy
Sub Import_Counts_csv_files()
Const strPath As String = "H:\My Documents\Gatwick\Database\counts\test" '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
For intFile = 1 To UBound(strFileList)
DoCmd.TransferText acImportDelimi, , _
"counts", strPath & strFileList(intFile), HasFieldNames:=True
Next
MsgBox UBound(strFileList) & " Files were Imported"
End Sub
Thanks again in anticipation