Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A/P Batch - trap input errors

Status
Not open for further replies.

POSOL

Programmer
Jul 2, 2004
16
CA
Hi I am working on Invoice importing system for ACCPAC A/P.
I have a challenge for you:

When importing a batch (from external application) I can get to the point where the invoice that I importing has incorrect information (For example: Vendor ID, Invoice Nubmer, GL Account,...). When I try to import such a record I get run time error, catching it and NOW: the problem is: How to continue this importing proces? That is I whant to move on to the next record to import it, and just log that error record with that ID has that error.

P.S. I know that there is Cancel method available with which I probably can manage to solve problem, but I don't quite know how it work's

My routines:

APINVOICEheader.Fields("CNTBTCH").PutWithoutVerification (BatchNo)
APINVOICEheader.Fields("CNTITEM").PutWithoutVerification ("0")
APINVOICEheader.Browse "CNTBTCH = " + BatchNo, 1
APINVOICEheader.Fetch
APINVOICEheader.Fields("CNTITEM").PutWithoutVerification ("0")
APINVOICEheader.Init
APINVOICEheader.Fields("IDVEND") = Main.rstSourceDB![Vendor ID]

APINVOICEheader.Fields("IDINVC") = Main.rstSourceDB![Invoice]

APINVOICEheader.Fields("ORDRNBR") = Main.rstSourceDB![Work Order Number]
APINVOICEheader.Fields("INVCDESC") = Main.rstSourceDB![Invoice Description]
APINVOICEheader.Fields("DATEINVC") = Main.rstSourceDB![Due Date]

DoEvents

'setting up Fiscal Year and period
APINVOICEheader.Fields("FISCYR") = Year(Date)
APINVOICEheader.Fields("FISCPER") = Month(Date)


'populate detail1 (Table at the bottom of main tab in ACCPAC)
APINVOICEdetail1.Init
APINVOICEdetail1.Fields("IDGLACCT") = Main.rstSourceDB![GL Account]
APINVOICEdetail1.Fields("AMTDIST") = Main.rstSourceDB![Total]
APINVOICEdetail1.Fields("TEXTDESC") = Main.rstSourceDB![Comments]
'taxes
'APINVOICEdetail1.Fields("AMTTOTTAX") = Main.rstSourceDB![GST] + Main.rstSourceDB![PST]
'APINVOICEdetail1.Fields("AMTTAXTOBE") = Main.rstSourceDB![GST] + Main.rstSourceDB![PST]
'APINVOICEdetail1.Fields("AMTTAX1") = Main.rstSourceDB![GST]
'APINVOICEdetail1.Fields("AMTTAX2") = Main.rstSourceDB![PST]
[/color green]
APINVOICEdetail1.Insert
APINVOICEheader.Fields("AMTGROSTOT") = Main.rstSourceDB![Total]
APINVOICEheader.Insert
GoTo nextRecord

ACCPAC_Import_err:

ErrCount = Main.AccpacSession.errors.Count
If ErrCount > 0 Then
For j = 0 To ErrCount - 1
errorNumber = errorNumber + 1
Error = Main.AccpacSession.errors.item(j)
File.WriteLine (errorNumber & ". Importing Error: Record ID#: " _
& Main.rstSourceDB![ID] & " Invoice#: " & Main.rstSourceDB![Invoice] _
& ":" & vbCrLf & Replace(Error, vbLf, ""))
DoEvents
Next
Main.AccpacSession.errors.Clear
Else
errorNumber = errorNumber + 1
File.WriteLine ("Importing Error: Record ID#: " & Main.rstSourceDB![ID] _
& " Invoice#: " & Main.rstSourceDB![Invoice] & vbCrLf & Err.Description)
DoEvents
End If
'clear prev error
'APINVOICEheader.Cancel
'APINVOICEdetail1.Cancel
GoTo nextRecord_err

nextRecord:
imported = True
recordImported(i) = True

nextRecord_err:
[/color blue]


By the way If anybody tried to add taxes into invoice HOW, what fields are connected and what info should they contain? (Part of the code in green)

Thanks to everybody for the posts
 
Update on the previous post:

I was playing with Cancel method that is REMed at the end of the listing, and it actually can restart views for importing next invoice, BUT:

The thing is: You can import new invoices after error as long as you have all correct information in the invoices that follows, BUT when you reach next invoice with incorrect information subroutine falls of with error message (it doesn't even get cought by "error catcher")

I get following error message:
"Method 'Value' of object 'IAccpacViewField' failed"

Any Ideas?
 
I got the problem with restarting the process figured out
My mistake was that I was coding:

Goto ...
at the end of the error handling routine

should have...
Resume ...

:)

But I still have problem with adding Taxes import!?

any help will be appresiated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top