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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV Files - OPEN statement

Status
Not open for further replies.

bujin

MIS
Oct 2, 2000
144
GB
For the database I'm writing, I have got a CSV file from another database full of trainee names which I want to import into an Access database. The import side of things is fine - I know how to do that, but the problem I'm having is that the column headers in the text field are labelled

"T_NINUMB", "T_NAME2", "T_NAME1", "U_NAME", "T_PLO"

on the first line if the text file, but I want it to read

"NI", "Surname", "Forenames", "Employer", "TLO"

because that's the name of the column headers in the Access table to import into.

At the moment, I've just got a bit of code to open the file in Notepad and edit it manually, but I want to perform this operation automatically. How would I go about doing it? I suspect it has something to do with the Open statement, reading in the line, checking if it's the first line, if it is, changing it to the second line.

Any ideas on how to go about coding this?
 


Hi bujin


Cant you just use the advanced import options? You can create an import specification and then change the titles there and keep the saved specification for later use.

The import specifications can also be used in code.

Check it out.


Stew
 
Thanks Stew! I'll give it a look.

After I posted that, I came up with one solution - I used the Line Input statement to read in each line, then output it to a new file, but putting the correct column header in instead of the old one, then I deleted the old file and renamed the new one, before importing it as before. It seems a rather complicated way of doing it but it only takes around 15 lines of code anyway.

But I'll give your idea a look to see if I can fit it in.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top