I need to have my application add ar invoices and ap invoices to ACCPAC. We are using ACCPAC 5.5A 200. I started with AP invoices and created a macro. I took the macro and converted to .NET. The only data I modified is vendor id and the descriptions. I am just trying to test that I can add an AP Invoice from my code.
It creates the batch, but errors on the first PROCESSCMD line for the batch fields. The error is Object reference not set to an instance of an object.
I hope it is something I am just overlooking.
Thank you for your help.
Here is my compose and enter ap invoice code
It creates the batch, but errors on the first PROCESSCMD line for the batch fields. The error is Object reference not set to an instance of an object.
I hope it is something I am just overlooking.
Thank you for your help.
Here is my compose and enter ap invoice code
Code:
Private Sub OpenAndComposeAPInvoiceViews()
Try
mAPINVOICE1batch = mDBLinkCmpRW.OpenView("AP0020")
mAPINVOICE1batchFields = mAPINVOICE1batch.Fields
mAPINVOICE1header = mDBLinkCmpRW.OpenView("AP0021")
mAPINVOICE1headerFields = mAPINVOICE1header.Fields
mAPINVOICE1detail1 = mDBLinkCmpRW.OpenView("AP0022")
mAPINVOICE1detail1Fields = mAPINVOICE1detail1.Fields
mAPINVOICE1detail2 = mDBLinkCmpRW.OpenView("AP0023")
mAPINVOICE1detail2Fields = mAPINVOICE1detail2.Fields
mAPINVOICE1detail3 = mDBLinkCmpRW.OpenView("AP0402")
mAPINVOICE1detail3Fields = mAPINVOICE1detail3.Fields
mAPINVOICE1detail4 = mDBLinkCmpRW.OpenView("AP0401")
mAPINVOICE1detail4Fields = mAPINVOICE1detail4.Fields
Dim arViews(0) As Global.ACCPAC.Advantage.View
arViews(0) = mAPINVOICE1header
mAPINVOICE1batch.Compose(arViews)
ReDim arViews(3)
arviews(0) = mAPINVOICE1batch
arviews(1) = mAPINVOICE1detail1
arviews(2) = mAPINVOICE1detail2
arviews(3) = mAPINVOICE1detail3
mAPINVOICE1header.Compose(arViews)
ReDim arViews(2)
arViews(0) = mAPINVOICE1header
arViews(1) = mAPINVOICE1batch
arViews(2) = mAPINVOICE1detail4
mAPINVOICE1detail1.Compose(arViews)
ReDim arViews(0)
arViews(0) = mAPINVOICE1header
mAPINVOICE1detail2.Compose(arViews)
ReDim arViews(0)
arViews(0) = mAPINVOICE1header
mAPINVOICE1detail3.Compose(arViews)
ReDim arViews(0)
arViews(0) = mAPINVOICE1detail1
mAPINVOICE1detail4.Compose(arViews)
Catch ex As Exception
ErrorHandler(ex)
End Try
End Sub
Private Sub EnterAPInvoice()
Try
mAPINVOICE1batch.RecordCreate(1)
[COLOR=red]mAPINVOICE1batchFields.FieldByName("PROCESSCMD").SetValue("1", False) ' Process Command Code[/color]
mAPINVOICE1batch.Process()
mAPINVOICE1batch.Read(True)
mAPINVOICE1header.RecordCreate(2)
mAPINVOICE1detail1.Cancel()
mAPINVOICE1batchFields.FieldByName("BTCHDESC").SetValue("test description sent", True) ' Description
mAPINVOICE1batch.Update()
mAPINVOICE1headerFields.FieldByName("IDVEND").SetValue("1400", True) ' Vendor Number
mAPINVOICE1headerFields.FieldByName("PROCESSCMD").SetValue("7", False) ' Process Command Code
mAPINVOICE1header.Process()
mAPINVOICE1headerFields.FieldByName("SWCALCTX").SetValue("0", True) ' Tax Amount Control
mAPINVOICE1headerFields.FieldByName("IDINVC").SetValue("DOC NUM", True) ' Document Number
mAPINVOICE1headerFields.FieldByName("IDDISTSET").SetValue("TRDSHW", True) ' Distribution Set
mAPINVOICE1headerFields.FieldByName("ORDRNBR").SetValue("ORD NUM", True) ' Order Number
mAPINVOICE1headerFields.FieldByName("PONBR").SetValue("PO NUM", True) ' PO Number
mAPINVOICE1headerFields.FieldByName("INVCDESC").SetValue("test desc 2 sent", True) ' Invoice Description
mAPINVOICE1headerFields("PROCESSCMD").SetValue("3", False) ' Process Command Code
mAPINVOICE1header.Process()
mAPINVOICE1detail1Fields.FieldByName("CNTLINE").SetValue("-2", True) ' Line Number
mAPINVOICE1detail1Fields.FieldByName("CNTLINE").SetValue("-2", True) ' Line Number
mAPINVOICE1detail1.Read(True)
mAPINVOICE1detail1Fields.FieldByName("AMTDIST").SetValue("50.000", True) ' Distributed Amount
mAPINVOICE1detail1.Update()
mAPINVOICE1detail1Fields.FieldByName("CNTLINE").SetValue("-3", True) ' Line Number
mAPINVOICE1detail1.Read(True)
mAPINVOICE1detail1Fields.FieldByName("AMTDIST").SetValue("40.000", True) ' Distributed Amount
mAPINVOICE1detail1.Update()
mAPINVOICE1detail1Fields.FieldByName("CNTLINE").SetValue("-1", True) ' Line Number
mAPINVOICE1detail1.Read(True)
mAPINVOICE1headerFields.FieldByName("AMTGROSTOT").SetValue("90.000", True) ' Document Total Including Tax
mAPINVOICE1header.Insert()
mAPINVOICE1batch.Read(True)
mAPINVOICE1header.RecordCreate(2)
mAPINVOICE1detail1.Cancel()
Catch ex As Exception
ErrorHandler(ex)
End Try
End Sub