Import CSV with Import Specification

  • Thread starter Thread starter shmoussa
  • Start date Start date
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.
 
Look in VBA Help for the TransferText method. The second argument (I, think)
is the name of the saved import spec.
 
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?
 
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?
 
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.
 
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.
 
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.
 
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.
 
if you want to import CSV using a particular specification-- then you should
use SQL Server and BCP.exe
 
Back
Top