
import txt files in Access fails to read last line
Quote:
> You should post the code that handles the eof condition of the file.
> Depends on the looping code you use if it handles the last line or not.
> As you can see, when importing text files there are few gotchas that you
> have to deal with.
code is:
in the module:
==========
Property Get EOF() As Boolean
If Me.IsOpen Then
EOF = VBA.EOF(Me.Handle)
End If
End Property
in the form:
========
Private Sub cmdReadAll_Click()
Dim MyName As String
Dim MyDB As Database
Dim rs As Recordset
Dim objFile As clsTextFile
'open de poemtabel voor lezen en schrijven
Set MyDB = CurrentDb()
Set rs = MyDB.OpenRecordset("Poem", dbOpenDynaset)
rs.MoveFirst
'1st record in dir
MyName = Dir(MyPath)
Do While MyName <> ""
If InStr(1, MyName, ".txt") > 0 Then
'get the ID
rs.FindFirst "[ID]=" & Left(MyName, InStr(1, MyName, ".") - 1)
'zoek het bijbehorende record in de tabel poem
If Not rs.NoMatch Then
'open file
Set objFile = New clsTextFile
objFile.Path = MyPath & MyName
If objFile.FileOpen() Then
With rs
.Edit
Do Until objFile.EOF
!txtPoem = !txtPoem & objFile.Text & vbCrLf
objFile.ReadNext
Loop
objFile.FileClose
'write file to tabel
.Update
End With
End If
Set objFile = Nothing
Else
'open debugwindow (Ctrl-G)
Debug.Print "Fout: " & Left(MyName, 1)
End If
End If
'next file
MyName = Dir
Loop
Me.Subformulier_Poem.Requery
Me.cmdReadAll.Caption = "R E A D Y !!"
End Sub