records (lines) from a text file

B

Bill

Anyone have an example of how to read records (lines)
from a txt file in VBA code?

Like:

Dim strMyString as String
(define what? a file object?) MyTxtFile "c:\MyFolder\MyFile.txt"

strMyString = ReadLine.MyTxtFile

Do While MyTxtFile.EOF = False
..
.. (process code)
..
strMyString = ReadLine.MyTxtFile
Loop
 
M

Marshall Barton

Bill said:
Anyone have an example of how to read records (lines)
from a txt file in VBA code?

Like:

Dim strMyString as String
(define what? a file object?) MyTxtFile "c:\MyFolder\MyFile.txt"

strMyString = ReadLine.MyTxtFile

Do While MyTxtFile.EOF = False
.
. (process code)
.
strMyString = ReadLine.MyTxtFile
Loop


If your file is regular like a table, you can just use the
Open, LineInput/Input, Close, etc. statements (see VBA
Help).

If you want a Class object that allows to deal with all
kinds of parsing issues while reading the file, see:
http://www.mvps.org/access/modules/mdl0057.htm
 
B

Bill

Hi Marsh,

No wonder I couldn't find it, I was looking for "read".

While I was waiting to a reply post, I began the code
that parses the string to recognize what kind of record
was read and load up some local variables that are to
be used in SQL Inserts to build table records.

A partial code segment:
strSQL = "INSERT INTO
TopicHist(Session,Year,MtgNo,Topic,Chairman)"
strSQL = strSQL & " Values(" & rSession & "," & rYear & "," &
rMtgNo & ","
strSQL = strSQL & """" & rTopic & """," & """" & rChairman &
""")"

Debug.Print strSQL
CurrentDb.Execute strSQL

Produces:

INSERT INTO TopicHist(Session,Year,MtgNo,Topic,Chairman)
Values(April,1975,1,"Direction And Responsibilities","Jack Lane")

Run-time Error: '3061';
Too few parameters. Expected 1.

There are 5 variables and 5 values! What's missing?
There is an ID autonumber key defined in the table,
but I don't believe it's required in the insert. Correct?

Bill
 
D

Dirk Goldgar

Bill said:
There are 5 variables and 5 values! What's missing?
There is an ID autonumber key defined in the table,
but I don't believe it's required in the insert. Correct?

See my reply to your independent post of this question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top