Inputting data from file

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I'm using code in Access to read a text file. I need to read in a whole
line at a time regardless of what characters are in the line (spaces,
commas, etc.). I can use INPUT to read in a line but it ignores leading
spaces and breaks at commas. I can use INPUT # and read one character at a
time. Is there any way to read a whole line at one time like the old BASIC,
LINE INPUT command?
 
You can use a filesystem object to do that.

Dim fs, f As Object
Dim strLine As String

Set fs = CreateObject("Scripting.FileSystemObject")
strFileName = "\\servername\filepath\filename.txt"
Set f = fs.opentextfile(strFileName, 1, False, -2)

strLine = f.readline ' this reads the whole line
strLine = f.read(3) ' this reads the first 3 chars of line
strLine = f.skipline ' skips the next line

This should get you where you need to go....

Regards,
Jen
 
Thanks, that helped.

Now I need to know when I am at the EndOfFile. I couldn't find anything in
Help about the Scripting.FileSystemObject.
 
Back
Top