Import multiples csv files in one table

Copper Contributor

Hi everyone,

I have a code where we can import many csv files in one table, this works fine, but the user need to drop the files in a specific folder.

Is there a way to adapting the code below with a dialog function to allow the user to looking the Csv's files in any folder and then selected one or many at the same time to import in one table?

 

Thanks for helping

Carlos

------My Code------Access 365---------------

Private Sub Command74_Click()

Dim stLinkCriteria As String

Const strPath As String = "C:\" 'Directory Path

 Dim strFile As String 'Filename

 Dim strFileList() As String 'File Array

 Dim intFile As Integer 'File Number

 

DoCmd.SetWarnings False

 

 'Loop through the folder & build file list

strFile = Dir(strPath & "*.csv")

 

''''''' This line does not working

'''''''strFile = Application.GetOpenFileName(, 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)

 

'''''''Delete old data

DoCmd.RunSQL ("DELETE * FROM my table")

'''''''Import fresh data

DoCmd.TransferText acImportDelim, "mySpec  Import Specification", "MyTable", strPath & strFileList(intFile), 0

Next

MsgBox UBound(strFileList) & " Files were Imported"

End Sub

0 Replies