Using VB to parse a text file (1 Viewer)

Roni Sutton

Registered User.
Local time
Today, 01:09
Joined
Oct 18, 1999
Messages
68
I have used VB multiple times to copy data from a mainframe session to an Access table using Rumba Object X. I want to do something similar with a delimited text file. Can someone point me in a good direction regarding how to open the file in VB and how to reference the columns and rows? I need to read pieces of a row into various variables and then plan to use an Insert SQL statement to put that data into a table in an Access 2k db. Any ideas would be greatly appreciated.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:09
Joined
Feb 19, 2002
Messages
43,396
Access has a method that should work for you without any VBA coding. Look up the TransferText Method. If you import the file ONCE manually, you can create an import spec and save it. Then in your automated code you can refer to the import spec so that Access always knows how to interpret the data. The TranserText Method also works well for fixed format files although creating the import spec is a little more comples. If your data has date fields that are not in some easily recognized format, the import spec wizard will give you the option to specify field order and delimiter.
 

Roni Sutton

Registered User.
Local time
Today, 01:09
Joined
Oct 18, 1999
Messages
68
It is not a fixed length text file and will have to have some serious parsing done before being read into the fields. I don't want to use Access to begin the process because this is going to be an automatic job that runs nightly which I will set up with a batch file to kick off. I have used the import spec a lot and I'll look into using that and creating a timer kickoff from within the db. I wanted to avoid that if I could, though since it's not my db (long story). Thanks for the idea - I will certainly give it a whirl.
 

Users who are viewing this thread

Top Bottom