Importing multiple .csv files

IMO

Now Known as ___
Local time
Today, 07:34
Joined
Sep 11, 2002
Messages
723
Hi All and Happy New Year.

I'm a bit stuck. I need to import multiple .csv files on a daily basis for report printing. Each .csv file has the same format as the table and importing one file is not a problem but is there a way I could get the user to select the files which need to be imported and after selection click on a button which would then import the selected files and move the original files to another directory? Or, on the click of a button, all files in a particular directory are imported and the original files moved? Any help would be much appreciated as my deadline is 30th Jan.

Thanks in advance
IMO
 
I don't know how to *select* files to import by OnClick, which is what I think you want, but I have a feeling the FileSystemObject will allow you to move files, at the very least it'll let you Read/Create/Delete which will have the same effect, but probably take alot longer.

Here's a sample of some code I use to import some excel files to my db

Private Sub Import_Files_Click()
Importing.Visible = True

Dim FileName As String
Dim objFSO
Dim objFolder
Dim objFile

Me.FilesImported = Null

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("J:\Britvic File Import\File Imports\")

For Each objFile In objFolder.Files
Me.FilesImported = Me.FilesImported & objFile.Path & vbCrLf
DoCmd.RepaintObject acForm, "ImportForm"
FileName = objFile.Path
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel7, "Imported Files", FileName, True, "B39:U119"
Next

Importing.Visible = False
End Sub

I'd be interested how you get on (esp. OnClick Select) so let us know

Hope this has helped
 
Crosmill,
Thanks for your reply and sorry I didn't get back to you yesterday (loads to do). I managed to import all .csv files from one directory with this code :

Private Sub Command0_Click()

Dim InputDir, ImportFile As String, tblName As String

InputDir = "c:\MY DIRECTORY\"

ImportFile = Dir(InputDir & "\*.csv")

Do While Len(ImportFile) > 0
'tblName = Left(ImportFile, (InStr(1, ImportFile, ".") - 1)) 'This is to import each file into single tables.
tblName = "MY TABLE NAME" 'This is to import all files into one table.

DoCmd.TransferText acImportDelim, , tblName, InputDir & ImportFile, True

ImportFile = Dir
Loop


End Sub

I'm still working on the OnClick Select but as soon as I find a way I'll let you know
Cheers
IMO
 

Users who are viewing this thread

Back
Top Bottom