Reading data from within a report

W

Wendy

Hi

I need to extract data from a report and place it in my table. My main
problems are:- I don't know where the first Invoice No I want will be within
the report, I don't know how many pages of invoice numbers there will be or
where they finish. I do know the title on each page and the characters
which appear after the final invoice number.

My loop worked until I added the NextPageTitle variable it now tells me I
have a for without a next. But I can't see it.
Windows XP, Access 2000, external text file comes from customers mainframe.

Please help!

Thanks

Wendy

Function Read_Post()
Dim dbs As DAO.Database
Dim rstDWP As DAO.Recordset
Dim fname As String 'filename
Dim textline As String 'the line being read

Dim LineNoID As Integer
Dim J As Long 'J for Jump lines
Dim SearchChar As String
Dim SearchChar2 As String

' SETUP DATASET
Set dbs = CurrentDb
Set rstDWP = CurrentDb.OpenRecordset("Post", DAO.dbOpenDynaset)


fname = "C:\Postfile.txt" 'test file name
SearchChar = "Invoice No."
SearchChar2 = " PO616"
LastLine = "----------"

Open fname For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, textline

LineNoID = LineNoID + 1
mypos = InStr(1, textline, SearchChar, 15)
If mypos = 1 Then 'Mypos1 = Searching for first instance of
Invoice No
For J = 1 To 1
Line Input #1, textline ' Read line into variable.
Next J 'Invoice Number then blank line before
valid data

For J = 1 To 59 'For loop1
Line Input #1, textline ' Read line into
variable.

If NextPageTitle = InStr(1, textline,
SearchChar2, 12) Then 'PO616 then blank line
For K = 1 To 2 'For loop2
Line Input #1, textline
Next K 'skip next page lines For
loop2
If EndOfInvoice = InStr(1, textline, LastLine,
12) Then End 'Reaches last line and ends

With rstDWP 'add to the PO616 table
.AddNew
!Invoice_NO = Left(textline, 6)
!Amount = Mid(textline, 23, 8)
!Transaction= Mid(textline, 41, 11)
!Reason = Mid(textline, 106, 40)
.Update
End With
Next J 'For loop1 through each record on page


End If 'mypos Invoice No. search
Loop 'EOF Do
Close #1 ' Close file.

End Function
 
J

J_Goddard via AccessMonster.com

Hi -

I don't see where NextPageTitle or EndofInvoice are defined (Dim) or more
importantly, where they are getting values assigned to them. Are they global
variables defined elsewhere?

I think you are getting a misleading error message - where are the Endif's
that correspond to some of your If statements? I can only see one.



John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top