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