Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help in importing a text table via VBA 1

Status
Not open for further replies.

inso18

Technical User
Dec 30, 2006
147
IL
Hello All.

I have many text table files needed to be imported to the database, while the user would specify which text file table to import.

I created a VBA function with a parameter, which is for the text table file name. It doesn't work however:

Code:
 Function ImportTextTable(strFileName)
DoCmd.TransferText acExportDelim, , "tblNewTable", strFileName, True
End Function
I get the following error:
Run-time error '3011'
The Microsoft Jet database engine could not find the object 'tblNewTable'. Make sure the object exists and that you spell its name and path name correctly.


My problem here is, that I can't create a table beforehand because each text table file has different field names and different number of them.

Using a macro does the job, without requiring a table to created before hand:
Action: TransferText

Transfer Type: Import Delimited
Specification Name:
Table Name: tblNewTable
File Name: C:\Organization1.csv
Has Field Names: Yes
HTML Table Name:
Code Page:

But in macro I can't use a parameter in File Name field.

How can I do the job using VBA?

Please help.
Thanks,
inso18.
 
inso18,
[tt]acImportDelim[/tt]?

[tt]DoCmd.TransferText [red]acExportDelim[/red], , "tblNewTable", strFileName, True[/tt]

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
CautoionMP,
thanks for replying:

I need to Import text table file to the database, not to export.
 
Oops, my mistake, it really should be acImportDelim, but it doesn't work anyway.
 
Hehe, I'm sorry,
It does work with acImportDelim

And I didn't undestand why my text files are being deleted!

So all it was a typing mistake :]

Thanks CautionMP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top