New_to_this
New member
- Local time
- Today, 11:04
- Joined
- Nov 20, 2018
- Messages
- 7
HI,
I'm very new to this so please explain in simple terms!
I have found the code below to import multiple .csv files into one table but I now need to append the file name to each file once its been imported so I can keep a track, if this is possible and as I'm very new to all this could you insert the code into the one below, so I cant make any mistakes?
many thanks in advance
Sean
Sub Import_multiple_csv_files()
Const strPath As String = "C:\Addresspoint" '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, , _
"PETA VSK Merged", 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
I'm very new to this so please explain in simple terms!
I have found the code below to import multiple .csv files into one table but I now need to append the file name to each file once its been imported so I can keep a track, if this is possible and as I'm very new to all this could you insert the code into the one below, so I cant make any mistakes?
many thanks in advance
Sean
Sub Import_multiple_csv_files()
Const strPath As String = "C:\Addresspoint" '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, , _
"PETA VSK Merged", 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