Use: Exit Do
Example: If rs!Acc is empty, exit loop:
If Len(nz(rs!Acc,""))=0 then Exit Do
The condition can be as simple or complex as you want.
Program control immediately jumps to the command following Loop (i.e., Close
#fh)
HTH,
"Wendy" <(E-Mail Removed)> wrote in message
news:4c-(E-Mail Removed)...
> Hi I'm using a recordset to read a text file and input the data into an
> access 2000 table. My problem is I want the line input to treat a blank
> line as eof, there is information after the blank line but I don't need to
> import it.
> This is my code
>
> Function ap1()
> Dim Filepath As String
> Dim Currentfile As String
> Dim rs As DAO.Recordset ' Database
> Dim fh As Integer ' File handle
> Dim lc As Long ' Line counter
> Dim ln As String ' Actual line
> Dim sp As Long ' Position of first space
> Dim thefile As String 'full filename
>
> Filepath = "C:\temp\*.PO"
> Currentfile = Dir(Filepath)
> thefile = "c:\temp\" & Currentfile
>
> Set rs = CurrentDb.OpenRecordset("TblAllpay", dbOpenDynaset)
>
>
> fh = FreeFile
> lc = 0
> Open thefile For Input As #fh
> Line Input #fh, ln
>
> Do While Not EOF(fh)
>
> lc = lc + 1
>
> sp = InStr(ln, " ")
>
> rs.AddNew
> rs!Acc = 0 & Mid(ln, 9, 7)
> rs!Transdate = Right(ln, 10)
> rs!Amount = Mid(ln, 16, 16)
> rs!Details = Mid(ln, 2, Len(ln))
> rs!apfn = Currentfile
> rs.Update
>
> Loop
> Close #fh
>
> End Function
>
> Thanks
>
> Wendy
>
>
|