Import CSV with Import Specification

S

shmoussa

Please help. I seperated my three questions to keep this organized. I
want the data in a CSV file to be added to an already existing table.
I have created an import specification called "Disks" and the data
should be imported using that. But how can this be done? Thanks.
 
K

Klatuu

Look in VBA Help for the TransferText method. The second argument (I, think)
is the name of the saved import spec.
 
S

shmoussa

Thanks for the reply. I put this this into my command button.

To get the open dialog box:
strFile = GetOpenFile_CLT("C:\Disk Space", "Select the .csv file that
you want to import")

To do the transfer: DISKS is the name of the import specification.
TableNew is the table I want to import to.
DoCmd.TransferText acImportDelim, DISKS, TableNew, strFile, True

After the open dialog box pops up successfully, I select the file and
click okay. My error message says

The action or method requires a table name arguement.

I'm not sure how to fix this. Any ideas?
 
K

Klatuu

TableNew has to contain a table name whether it is a new table or an existing
table.
 
S

shmoussa

TableNew is the name of the table I want to import to. Isn't that what
it wants?

DoCmd.TransferText acImportDelim, DISKS, TableNew, strFile, True

Am I supposed to do something within my table TableNew or do something
to this code?
 
K

Klatuu

Just had a thought.
Is TableNew the actual name or is it a variable containing the name?
If it is the actual name, it needs to be in quotes.

DoCmd.TransferText acImportDelim, DISKS, "TableNew", strFile, True

Same would be true for DISKS.
 
S

shmoussa

Okay the quotes worked and it imported into my table. My CSV file has
field names inside of it. Is there anyway to tell the code to ignore
my headings (the first line) of my CSV file and use the headings that
are predefined in the table?

Thanks so much for your constant, quick replies.
 
K

Klatuu

shmoussa said:
Okay the quotes worked and it imported into my table. My CSV file has
field names inside of it. Is there anyway to tell the code to ignore
my headings (the first line) of my CSV file and use the headings that
are predefined in the table?

Thanks so much for your constant, quick replies.
 
K

Klatuu

The True at the end should tell it the first row is field names. When
importing to an existing table, it should not import those names.
 
G

Guest

if you want to import CSV using a particular specification-- then you should
use SQL Server and BCP.exe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top