Import text file

racdata

Registered User.
Local time
Today, 07:50
Joined
Oct 30, 2002
Messages
74
Import text file - Help please!!

Hi all

I would like to know if I can import a text file into Access

The file extention is *.prn. It is a text file

Thanx
Arrie
 
But offcourse....

Just use the file import command from the menu...

Greets

The Mailman
 
Of course you can!!
I will give you the starting point and you will have to read the help to reach your desired result.
Here is a sample code from one of my projects.

DoCmd.TransferText acImportFixed, "File import Specification", _
"Inventory", "File.txt"
where "Inventory" is the name of the table, file.txt is the name of the file to import. The file import specs is stored inside the access database itself with a name you choose, and it specifies the number of fields, the width and datatype of each field, etc. and you reach it by choosing File-> get external data-> import-> text files and then continue with the wizard.
This solution works if you need to import text programmatically, like in situations where the user is importing data from another source. Typical situation is hand held machines which transfer their data to the PC at the end of the day.
For simple, one-time imports, File-> get external data-> import will do the job.
 
Last edited:
Access (actually Jet to be precise) insists on a very small lsit of acceptable extensions. I doubt that .prn is one. You have two choices, change the extension or modify the registry to accept other extensions.
 
Another option is to use the VB capabilities in Access to open the file and read it record by record as in the following samples

Open filename.prn For Input As #1
Do Until EOF(1)

table.AddNew
table!filed1 = Input(lenght1, #1)
table!field2 = Input(lenght2, #1)
.
.
.
table.Update
If Not EOF(1) Then cr = Input(2, #1)
Loop
table.Close
Close #1

VB has several ways of reading records from a file. This method is for fixed length field and note that you need to read the carriage return to move the pointer.
There is functions also to read from delimited, variable lenght fields.
 
Pat,

Not true, you can change to whatever extension you want!

If you have a .xls file you can import it as a text file if you so desire, no problem. (You dont get much 'workable' data, but you can do it)

As long as your sure its a text file you can import it as a text file.

Regards
 
I didn't say that Access couldn't read the .prn file, only that Jet recognizes a limited set of file extensions. This is by design and was implemented by an update to Jet around two years ago. If you change a file's extension to one that Access recognizes, Access will read it. Not necessarily well unless the file is actually text. Changing a .prn extension to .txt won't do you much good unless the .prn file contains text data but Access will open the file.
 

Users who are viewing this thread

Back
Top Bottom