Importing Multiple CSV Files

  • Thread starter Thread starter carl
  • Start date Start date
C

carl

I have 30 CSV files - all formated the same. Is there a way to import them in
one shot and have all the data records contained in one database ?

Thank you in advance.
 
I have 30 CSV files - all formated the same. Is there a way to import them in
one shot and have all the data records contained in one database ?

Thank you in advance.

something like this should work....
Private Sub Command0_Click()

Dim strFile As String
Dim strPath As String

strPath = BrowseFolder("Choose a directory...")

strFile = Dir(strPath & "\*.csv")
Do Until strFile = ""
strFile = Dir
'Replace the name of your saved import specification and
tablename...
DoCmd.TransferText acImportDelim, "MySavedSpecName",
"DestinationTable", strFile, False
Loop


End Sub
 
Thank you.

I found this but when run, the resulting access table is not separated into
itto fields.

My regional setting for separator is ";" semicolon. The file csv files I am
trying to import are ";" separated as well.

What am I doing wrong ?



Sub Import_multiple_csv_files()
'Modified from WillR - www.willr.info (December 2004)

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, , _
"Test", 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
 
Thank you.

I found this but when run, the resulting access table is not separated into
itto fields.

My regional setting for separator is ";" semicolon. The file csv files I am
trying to import are ";" separated as well.

What am I doing wrong ?

Sub Import_multiple_csv_files()
     'Modified from WillR -www.willr.info(December 2004)

    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, , _
        "Test", 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

Did you create the named import specification before running the code?
 
Back
Top