CSV Import with duplicate field names

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I am trying to import a CSV file in VBA and am having a few problems
with one of the imports. The .csv file contains row headers and there
are 7 rows titled "Descriptive Text." When I try to run the code:

DoCmd.TransferText transfertype:=acImportDelim, _
TableName:=strTable, _
FileName:=strTextFile, _
hasfieldnames:=True

I get an error: "Error No: 3063: Duplicate output destination
'Descriptive Text'.

The table that I am importing to has field names of Descriptive text,
Descriptive text 2, etc...

I only need the data that is listed in the first two descriptive text
columns. Is there any way to specify what columns to import or a way
of not importing the first row headings and skipping to row number 2?

Thanks a bunch in advance.

Mike
 
Hi Mike,
if this is a once-off import, you can rename the headers in the csv file.

You could try it with Has Field Names set to False, and Access can use the
default field names like F1, F2, etc.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Unfortunately this is a daily import, and needs to be as automated as
possible. I did try Has Field Names set to False but then the first
row imported had data that didn't match the data type. Any other
suggestions? Thanks again.

Mike
 
Mike, the technique below (by Doug Steele) could be more helpful to you that
trying to import using transfer text.
I haven't tried the following technique, but I have often seen it
recommended on the access discussion groups.

At this line in the code:
' strBuffer now contains a line of data: work with it
search for the columns you want to import (for this row) and write them to
your table into the fields you wish.
You could do a search on importing files this way to dig up some more code
routines to parse the data.

--------------------------------
The following VBA code will read a file line by line into variable
strBuffer.

Dim intFile As Integer
Dim strBuffer As String
Dim strFile As String

strFile = "C:\My Folder\MyFile.html"

intFile = FreeFile()
Open strFile for Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strBuffer
' strBuffer now contains a line of data: work with it

Loop

Close #intFile
 
Back
Top