PC Review


Reply
Thread Tools Rate Thread

Blank lines on line input

 
 
Wendy
Guest
Posts: n/a
 
      24th May 2007
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


 
Reply With Quote
 
 
 
 
George Nicholson
Guest
Posts: n/a
 
      24th May 2007
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
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
blank line in a query for blank lines in a report Sandi Microsoft Access Queries 4 4th Jan 2006 08:12 PM
line input problem-need to return 5 lines after a string is found festdaddy Microsoft Excel Programming 3 8th Dec 2005 04:38 PM
can we add a blank line after every...lines? Bob Phillips Microsoft Excel Programming 3 30th Aug 2004 06:23 AM
blank lines after city line Microsoft Outlook 0 12th Aug 2004 05:41 PM
Re: Blank lines in an address line Stevo Microsoft Access Reports 1 21st Oct 2003 12:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:41 AM.