Import data from csv

gbucknall

New member
Local time
Today, 12:01
Joined
Jul 12, 2006
Messages
6
I want to import data into a table from a csv file. The table is failry lengthy but to try this out I have the following:

tblTest - the table I want the data to end up in
tblTestcsv - the intermediate table I empty then put the csv data into
test.csv - the csv file (obviously)

I have used somde code which gets the data into the tblTestcsv OK but then doesn't move it into the tblTest - I get an error each time.

Dim sSql As String

DoCmd.TransferText acImportDelim, , "tblTestcsv", sFileLocation, False

sSql = "INSERT INTO tblTest (forename,surname,phone) " & _
"SELECT F2,F3,F4" & _
"FROM tblTestcsv"

CurrentDb.Execute sSql

Any help as to waht I am doing wrong would be gratefully received.
 
gbucknall said:
sSql = "INSERT INTO tblTest (forename,surname,phone) " & _
"SELECT F2,F3,F4" & _
"FROM tblTestcsv"
You need a space after F4

Otherwise you need to give us an error message or some guidance as to what happens. Does the tblTestCsv get created / filled?
 
Thanks - I am now one stage further but still with an error.
I have added the space but the error message I get is:

Too few parameteres. Expected 1.

The temmporary tabe contains 3 fields F1-3 and the final table (tblTest) contains 4 - the id, then forname, surname, phone)

Any further ideas?
 
when you have your first table loaded, design an access query to load that into the table, then

docmd.openquery myqry

you can check the query SQL syntax then if you want to see it.
 

Users who are viewing this thread

Back
Top Bottom