Reading in a text file

GregSmith

Registered User.
Local time
Today, 17:05
Joined
Feb 22, 2002
Messages
126
I have a text file in the following format:

lastname
firstname
middlename
employeenumber
hiredate

etc...

I have a combo box with a dropdown of all the employee names.
When you select a name, it opens the correct text file and should pull in the information.

I am getting a runtime error 62
Input past end of file

Here is my code:

Private Sub EmployeeName_AfterUpdate()

Dim Line1, Line2, Line3
Open "c:\attendance\name.txt" For Input As #1 ' Open file.

Do While Not EOF(1) ' Loop until end of file.

Line Input #1, Line1 ' Read line into variable.
Line Input #1, Line2
Line Input #1, Line3

Loop
Close #1 ' Close file.

Me.[LastName] = Line1 ' Update fields
Me.[FirstName] = Line2
Me.[MiddleName] = Line3

End Sub
 
I have noticed that the data does read in.
How do I pull it out?
 
Greg,

Code:
I have a text file in the following format: 

lastname 
firstname 
middlename 
employeenumber **Note: At least five lines per employee ...
hiredate 

etc... 

I have a combo box with a dropdown of all the employee names. 
When you select a name, it opens the correct text file and should pull in the information. 

I am getting a runtime error 62 
Input past end of file 

Here is my code: 

Private Sub EmployeeName_AfterUpdate() 

Dim Line1, Line2, Line3

**Note:  The input file is constant, not related to the combo ...

Open "c:\attendance\name.txt" For Input As #1 ' Open file. 

Do While Not EOF(1) ' Loop until end of file. 
   Line Input #1, Line1 ' Read line into variable. 
   Line Input #1, Line2 
   Line Input #1, Line3 
   ** Note: reads in groups of threes, not "at least five" as above
   ** Note: does Nothing with each person (only 3 lines!)
   Loop 
Close #1 ' Close file. 

'
' **Note: At end of file save random last three lines to the following
'         variables:
'         It is random because the loop reads in 3's and the data is in at
'         least groups of five or more.
'
Me.[LastName] = Line1
Me.[FirstName] = Line2 
Me.[MiddleName] = Line3 

End Sub

I can't really tell what you are trying to do. If the data was in groups of threes
then you would be putting the last person on your screen variables.

Since the data is in at least fives, then when you hit EOF you will put random
fields onto your screen

If you can show a test file and define what you are trying to do, we can
make this work.

Wayne
 
Hi Wayne,

Thanks for the reply.
What I ended up doing was:

Dim Line(255)

Open file for input
Do While Not EOF(1)
x = x + 1
Input #1, Line(x)
Loop

Close #1

It allowed me to put everything in an array and use it.
 

Users who are viewing this thread

Back
Top Bottom