Re: more on reading csv file into access
- From: "Dave O." <nobody@xxxxxxxxxxx>
- Date: Tue, 18 Sep 2007 10:42:36 +0100
Of course you get an error, you are assigning an array to a single string,
how on earth is it supposed to output the array, there is no magic where VB
can guess what you want and then format each element of the array and
present it correctly - YOU have to do all of that yourself. Each string
entry will need apostrophes, any dates will want # signs, each value will
need some sort of delimitation and you must iterate through the array
appending each element.
Here is a suggestion, take a random line from your file, now by hand work
out the SQL needed to add that to the database, once you have some good
working SQL you can then design the routine to generate that SQL. Trying to
write this sort of routine without knowing exactly what you need is doomed
to fail.
Regards
Dave O.
"inquirer" <noreply@xxxxxxxxxxx> wrote in message
news:46ef745e$0$13999$afc38c87@xxxxxxxxxxxxxxxxxxxxxxx
Further to my earlier post, I have a final (I hope) problem in actually
importing a csv file into Access (using vb6).
In the code below I get a "type mismatch" error when I try to run it at
the "&" before dataVals in the query
Dim dataVals() As String
Dim query as string
Do While Not EOF(1)
Line Input #1, txtNames
dataVals = Split(txtNames, ",")
query = "SELECT * INTO " & tblName & " IN '" & dbName & "' FROM " &
dataVals
dbBlock.Execute query
Loop
dbBlock.Close
tblName is the name of the table I want to insert the data into and dbName
is the full path to the database.
I do not know how to get the array of data values (dataVals) into the
query. The Split function is doing everything ok.
I have defined dataVals as a string array but the actual fields in the
data file are a mixture of numbers and text fields. I have set up the
table in Access so each field is correctly defined an number or text so
will the fact that dataVals is defined as strings cause a problem?
Note that in different data files there will be different numbers of
fields - that is ok as the creation of the table in the database takes
care of that.
Any help appreciated
Thanks
Chris
.
- References:
- more on reading csv file into access
- From: inquirer
- more on reading csv file into access
- Prev by Date: VB Chinese Code Problem
- Next by Date: Re: VB Chinese Code Problem
- Previous by thread: more on reading csv file into access
- Next by thread: VB Chinese Code Problem
- Index(es):
Relevant Pages
|