My code is running but the values are not inserted into the
test_table I created.. Initially when I tried to import with fixed
[quoted text clipped - 19 lines]
Is there a simple way to read this csv file with VBA?
You decide if the import is fixed or delimiterd in some way.
I see no comma's in what you posted so am guessing you got six
fields from line one by picking a space as a delimiter.
I'd stick with that and work form that table.
If not you will need to use OPEN amd Line Input
Here is some sample code,
Dim Textline
<HERE YOU OPEN THE TABLE(S) YOU WANT TO WRITE THE DATA TO>
Open "C:\TESTFILE.txt" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
<MORE CODE GOES HERE>
Debug.Print TextLine ' Print to the Immediate window.
Loop
Close #1 ' Close file.
Where MORE CODE appears you will have to,
add a new record to your table with .addNew
For I = 1 to 9
parse each line with mid or split
set the values from your parsing rountine to the field names
(covered in a previous post
Use .Update to write the new record.
Next I
You could do all 13 rows but it appears that 9 through 13 should be
related records in another table.
So for I = 1 to 5 go through the same process writing the results to
a second table using teh key from the other table.
Failure to relate these records (if they are related) *WILL*
continue to cause problems, especially when it comes to reporting.
You would have to write code to answer a simple question.
How many tests were marked "Undetermined"
As for it being a simple way, I think so, just a lot of busy work,
but I've been writing this type of import routine since dBase II on
an Osborne I and I did something similar on an IBM 1620.
I would have no problem asigning such a task to a student who wanted
to learn about looping through files and tables and using some of
the string handling functions of VB
One more comment. I rarely use loops in such events.
I would use 13 Line Input commands, parse the info then write it to a
record.
That way the code "looks" like what you are importing and errors cn
be easy to spot.