Import CSV file to an access table

Per_

Board Regular
Joined
Sep 16, 2011
Messages
90
Hello all, I would like to import an CSV file (see below) to an table in access with the command below. I only get one field name in the table with the
name: Header1;Header2. How can I get two field name: Header1 and Header2?

/P

Command
========
VBA Code:
DoCmd.TransferText _
        TransferType:=acImportDelim, _
        TableName:="TEST", _
        FileName:="C:\TEST.CSV", _
        HasFieldNames:=True

CSV file
=======
Code:
Header1;Header2
1;2
 
Last edited by a moderator:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You need an "Import Specification" since CSV file is semicolon delimited.

To create the specification you need to attempt importing the data manually once, so you can save the specification, and use it with the VBA code later.
  1. Select External Data -> New Data Source -> From File -> Text File
  2. Browse and select the CSV file to import into your table.
  3. Then the Import Text Wizard dialog is opened. Set the import properties, but do not close the wizard yet.
  4. Click on Advanced button at the bottom left. This opens the specification dialog.
  5. Click Save As, name it properly, for example "SemiColonImportSpec", and save it.
  6. Now you can cancel the import since all we need was saving the specification file.

Go back to your VBA code, and include one more parameter, which is called : SpecificationName:

VBA Code:
DoCmd.TransferText _
TransferType:=acImportDelim, _
SpecificationName:="SemiColonImportSpec", _
TableName:="TEST", _
FileName:="C:\TEST.CSV", _
HasFieldNames:=True
 
Upvote 1

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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