1
votes

I have multiple csv files (semicolon separated) with same number of columns(around 616) and different number of rows. I want to import every file into different tables in Access. I am totally new to macro/vba. I have faced two problems:

  1. I used this code [https://superuser.com/questions/1131994/ms-access-2016-import-multiple-csv-files][1] from a forum, it works fine but it's importing one csv file into one table in one column with semicolon separated (means 616 columns from csv file are showing in one coulmn in access with semicolon separated). although the data should be shown in separate columns of a table. I want the data to be shown in separate columns. After import, I am seeing the data in access same as csv file. The column heading in csv file has text and numbers (1 to 600) also.
  2. Secondly, I want to import some specific columns from csv file. Could someone please edit this code and add some coding how to import specific columns from csv file into Access.

I hope I explained well.

1
You will have to normalise your data layout - you can only have a maximum of 255 fields in access. That many columns indicates a poor storage method. Have a read here techrepublic.com/article/… for some guidance on importing data into AccessMinty
thank you for sending me this article. I am new to Access. I really didn't knew that it has a max. limit of 255 fields. Now i understood better.Abdul

1 Answers

0
votes

There is no way you can import files with 600+ columns into Access. You can try SQL Server. Alternatively, you can import the specific fields that you need. I seriously doubt you need 600+ fields in your data sets.

Anyway, you can export specific fields from Excel to Access.

Sub DAOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
    Set db = OpenDatabase("C:\FolderName\DataBaseName.mdb") 
    ' open the database
    Set rs = db.OpenRecordset("TableName", dbOpenTable) 
    ' get all records in a table
    r = 3 ' the start row in the worksheet
    Do While Len(Range("A" & r).Formula) > 0 
    ' repeat until first empty cell in column A
        With rs
            .AddNew ' create a new record
            ' add values to each field in the record
            .Fields("FieldName1") = Range("A" & r).Value
            .Fields("FieldName2") = Range("B" & r).Value
            .Fields("FieldNameN") = Range("C" & r).Value
            ' add more fields if necessary...
            .Update ' stores the new record
        End With
        r = r + 1 ' next row
    Loop
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
End Sub