import/read a text/prn file from line, say, 5

H

hccatmo

How do I use vba to read/import text/prn file:
1. cvs; or
2. fix length
starting from line 5 and
3. into a table with field named Name01, Name02,...
Thanks.
cg
 
G

gllincoln

Hi -

The short answer is - you don't do that (import a print file starting on an
arbitrary line with an unknown format).

Reality - if you can write a program that will open the file and read it
into a string variable one line at a time, then you can do practically
anything you can devise and want to do with your text string/row.

Assuming (from the question) that you aren't a programmer - and you are
trying to use the file import process of Access - I would recommend opening
the file in Notepad, delete the first however many lines and save it.

However, what about a footer? You may have to clean up/ delete the last
couple lines of the page as well.

Note: if the file contains more than one page worth of rows - look out for
repeating header and footer data on each page. I've paged through a dozen
pages deleting the footer and next header lines, to make something like this
work. If it is a one time project it isn't worth writing the code to
accomplish this automatically. If this is something you will regularly need
to do then you want to write (or have someone else write) a little function
to parse out the data into a format that Access will readily absorb.

If you are lucky, you will find that the edited file will then be a
fixed-length per column document that you can import using the fixed-length
import process. When you get all of the field lengths right - be sure to
save the resulting schema with a name you can remember - because next time,
you can open and use that schema instead of having to do that part again.

I would save it as a new table, make sure I got the lengths right by looking
at my new table, make sure the data looks right / is lined up right, then
use a query to append that data to the intended target table.

Visually scan the whole import table, sometimes a fixed length import column
will shift one right or left on you at some point, even thought the first 20
or 50 or 100 records came through perfectly.

Hope this helps...

Gordon
 

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