W
Wendy
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
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