The following code is suppose to read a text file.
The problem is that the code is only reading the first line. The other lines are not getting read.
Second problem is that the .Fields(Counter) = Now is not working. The error says data type conversion error, which I do not understand since the second data field is Date/Time type and the format is General Date (which is what Now returns).
And the third problem is that the date field from the text file does not get transferred correctly. It is converted to 1/1/2009 no matter what the date is.
Here is what the text file looks like:
105 1 1 4/12/2008 2 0 0 1
2009 2 3 4/13/2008 5 0 2 0
3004 4 2 3/27/2008 3 2 0 0
Actually, the date field is suppose to look like
4/12/2008 5:30pm instead of just 4/12/2008. But I can't event get the simple one read correctly. I tried putting quotes around the date ("4/12/08" and also "4/12/2008 5:30pm"). Can someone help, please?
Dim DataRead, db, rst, Counter
Set db = CurrentDb
Set rst = db.OpenRecordset("SELECT * FROM PDALOGS")
With rst
Open "pdalog.txt" For Input As #1
While Not EOF(1)
For Counter = 1 To 8
Input #1, DataRead
.AddNew
If Counter = 2 Then
.Fields(Counter) = Now
ElseIf Counter = 5 Then
.Fields(Counter) = CDate(DataRead)
Else
.Fields(Counter) = DataRead
End If
Next
.Update
Wend
Close
.Close
End With