text file import problem

T

Tom

I'm trying to import a text file. Here's a sample:

"89","000000","890828","01","PER"," .00"," .00","END="
"89","000001","890828","01","PER"," .00"," .00","END="
"89","000002","890828","01","PER"," 2755.12"," 2755.12","END="

And here's my code:

'------------------------------------------------------------
' import the dadgum text file with our data
'
Set DAOrs = DAOdbs.OpenRecordset(strTblName)

DoCmd.TransferText acImportDelim, , strTblName, strPathName, 0

DAOrs.Close
Set DAOrs = Nothing

which is *supposed* to tell Access (2k) that my file has no field names. But I
keep getting this error:

Field 'F1' doesn't exist in destination table '<MyTableName>'. I get the same
msg for all my input files.

Anyone know what I'm missing? Doing? Not doing?

Thanks in advance,

Tom
 
D

Dirk Goldgar

Tom said:
I'm trying to import a text file. Here's a sample:

"89","000000","890828","01","PER"," .00"," .00","END="
"89","000001","890828","01","PER"," .00"," .00","END="
"89","000002","890828","01","PER"," 2755.12"," 2755.12","END="

And here's my code:

'------------------------------------------------------------
' import the dadgum text file with our data
'
Set DAOrs = DAOdbs.OpenRecordset(strTblName)

DoCmd.TransferText acImportDelim, , strTblName, strPathName, 0

DAOrs.Close
Set DAOrs = Nothing

which is *supposed* to tell Access (2k) that my file has no field
names. But I keep getting this error:

Field 'F1' doesn't exist in destination table '<MyTableName>'. I get
the same msg for all my input files.

Anyone know what I'm missing? Doing? Not doing?

Thanks in advance,

Tom

You need to create an import specification, and give the name of that
specification in your call to TransferText. If you don't, Access uses
the default target field names that the import wizard uses: F1, F2, F3,
etc.

Incidentally, I don't see what you are trying to accomplish by opening a
recordset on the target table before importing, and then closing it
afterward. This is not a necessary part of the import.
 
T

Tom

You need to create an import specification, and give the name of that
specification in your call to TransferText. If you don't, Access uses
the default target field names that the import wizard uses: F1, F2, F3,
etc.

In all the reading I did, I *thought* that the spec was optional...but
the import would still work if the table existed. I understand I was
wrong.
Incidentally, I don't see what you are trying to accomplish by opening a
recordset on the target table before importing, and then closing it
afterward. This is not a necessary part of the import.

I thought I needed to. I stand corrected.

Thanks a lot,

Tom
 
D

Dirk Goldgar

Tom said:
In all the reading I did, I *thought* that the spec was optional...but
the import would still work if the table existed. I understand I was
wrong.

That's how I'd have interpreted the help topic for the TransferText
method on first reading, too. The help topic for the TransferText
*action* is a little clearer.
 

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