Import CSV files into table from Multi Select List Box?

stu999

Board Regular
Joined
Aug 28, 2008
Messages
183
Hi
What I would like to do is to import multiple CSV files into a table to use to create reports from selected result CSV files.

I have created the list box looking at the location and listing all files there and can get it to clear the table and import one CSV.

Just need some guidance on the best way to import more than one CSV into the table?

My code for importing one file is:
Code:
Private Sub bttnCSV_Click()
Dim mySQL
mySQL = "DELETE * FROM ArgonMonitor"
DoCmd.RunSQL mySQL
DoCmd.TransferText acImportDelim, , "ArgonMonitor", aFileList, True
End Sub
 
Private Sub Form_Load()
Call ListFiles("C:\Temp\ftpargon", , , Me.aFileList)
End Sub
Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If you have a subroutine (called ImportRoutine in this example) used to import one file, you can loop through the list box and run it on each file selected, i.e.

Code:
Dim x As Variant
With Me.aListfile
    If .ItemsSelected.Count > 0 Then
        For Each x In .ItemsSelected
            ImportRoutine (.ItemData(x))
        Next
    End If
End With

Just make sure you run the delete query outside of the Import subroutine, otherwise you will effectively only import the last file selected.
 
Upvote 0
Thanks for your help, got it working, here is my working code for reference.
Code:
Dim x As Variant
With Me.aFileList
    If .ItemsSelected.Count > 0 Then
        For Each x In .ItemsSelected
            DoCmd.TransferText acImportDelim, , "ArgonMonitor", aFileList.ItemData(x), True
        Next
    End If
End With
:cool:
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top