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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie - Create AP Invoice .NET 1

Status
Not open for further replies.

jjmbosslm

Programmer
Oct 28, 2008
25
US
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
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
 
Yes, sessions, views and dblinks have a .Close you should use, and I always set everything to Nothing. So whatever you open you should close and set to nothing.
 
Ah sorry, you are .Net, I'm thinking in VB6.
But surely there should still be a .Close method?
 
I thought so too. This is what AccPac techincal help suggested.

"You can just set the dblink objects to nil and the garbage collector will take care of the disposing it. There is no close method.
 
I am now adding customer and ship to data.

A couple of questions

1. This code below seems to work, but do you see anything wrong?
2. Is there a way for AccPac to auto assign customer ids and ship to loc ids?
3. If so what is the best way to retrieve this info after it has been inserted.
4. What is the best way to update this data...I assume by getting record, updating fields and calling update?

Thanks again

Code:
 mARCUSTOMER12header = mDBLinkCmpRW.OpenView("AR0024")
            mARCUSTOMER12detail = mDBLinkCmpRW.OpenView("AR0400")
            mARCUSTSTAT13 = mDBLinkCmpRW.OpenView("AR0022")

            mARCUSTSHIP1header = mDBLinkCmpRW.OpenView("AR0023")
            mARCUSTSHIP1detail = mDBLinkCmpRW.OpenView("AR0412")


            Dim arViews(0) As Global.ACCPAC.Advantage.View
            arViews(0) = mARCUSTOMER12detail
            mARCUSTOMER12header.Compose(arViews)

            ReDim arViews(0)
            arViews(0) = mARCUSTOMER12header
            mARCUSTOMER12detail.Compose(arViews)

            ReDim arViews(0)
            arViews(0) = mARCUSTSHIP1detail
            mARCUSTSHIP1header.Compose(arViews)

            ReDim arViews(0)
            arViews(0) = mARCUSTSHIP1header
            mARCUSTSHIP1detail.Compose(arViews)


            mARCUSTOMER12header.RecordCreate(Global.ACCPAC.Advantage.ViewRecordCreate.DelayKey)
            mARCUSTSTAT13.RecordCreate(Global.ACCPAC.Advantage.ViewRecordCreate.Insert)
            mARCUSTSTAT13.Fields.FieldByName("CNTYR").SetValue("2008", False)           ' Year
            mARCUSTSTAT13.Fields.FieldByName("CNTPERD").SetValue("10", True)                         ' Period,
            mARCUSTOMER12header.Fields.FieldByName("IDCUST").SetValue("66", True)                       ' Customer Number

            mARCUSTOMER12header.Fields.FieldByName("NAMECUST").SetValue("test66", True)                ' Customer Name

            mARCUSTOMER12header.Fields.FieldByName("IDGRP").SetValue("RTL", True)                      ' Group Code
            mARCUSTOMER12header.Fields.FieldByName("TEXTSTRE1").SetValue("add1update", True)                  ' Address Line 1
            mARCUSTOMER12header.Fields.FieldByName("TEXTSTRE2").SetValue("add2", True)                 ' Address Line 2
            mARCUSTOMER12header.Fields.FieldByName("NAMECITY").SetValue("city", True)                ' City
            mARCUSTOMER12header.Fields.FieldByName("CODESTTE").SetValue("state", True)               ' State/Prov.
            mARCUSTOMER12header.Fields.FieldByName("CODEPSTL").SetValue("65443", True)                  ' Zip/Postal Code
            mARCUSTOMER12header.Fields.FieldByName("CODECTRY").SetValue("USA", True)                ' Country
            mARCUSTOMER12header.Fields.FieldByName("TEXTPHON1").SetValue("3145642145", True)           ' Phone Number
            mARCUSTOMER12header.Fields.FieldByName("TEXTPHON2").SetValue("6362541452", True)          ' Fax Number
            mARCUSTOMER12header.Fields.FieldByName("NAMECTAC").SetValue("contact", True)           ' Contact Name

            mARCUSTOMER12header.Fields.FieldByName("CODETAXGRP").SetValue("USDTAX", True)              ' Tax Group

            mARCUSTOMER12header.Insert()



            mARCUSTSHIP1header.RecordCreate(Global.ACCPAC.Advantage.ViewRecordCreate.DelayKey)


            mARCUSTSHIP1header.Fields.FieldByName("IDCUST").SetValue("66", False)     ' Customer Number

            mARCUSTSHIP1header.Fields.FieldByName("IDCUSTSHPT").SetValue("1", True)                  ' Ship-To Location

            mARCUSTSHIP1header.Fields.FieldByName("NAMELOCN").SetValue("testship1", False)   ' Description
            mARCUSTSHIP1header.Fields.FieldByName("TEXTSTRE1").SetValue("shipadd1", False)   ' Address Line 1
            mARCUSTSHIP1header.Fields.FieldByName("TEXTSTRE2").SetValue("shipadd2", False)   ' Address Line 2
            mARCUSTSHIP1header.Fields.FieldByName("NAMECITY").SetValue("shipcity", False)   ' City
            mARCUSTSHIP1header.Fields.FieldByName("CODESTTE").SetValue("shipstate", False)   ' State/Prov.
            mARCUSTSHIP1header.Fields.FieldByName("CODEPSTL").SetValue("44444", False)   ' Zip/Postal Code
            mARCUSTSHIP1header.Fields.FieldByName("CODECTRY").SetValue("usa", False)    ' Country
            mARCUSTSHIP1header.Fields.FieldByName("TEXTPHON1").SetValue("1111111111", False)   ' Phone Number
            mARCUSTSHIP1header.Fields.FieldByName("TEXTPHON2").SetValue("2222222222", False)   ' Fax Number

            mARCUSTSHIP1header.Insert()
 
1. It looks good, but the I am one beer strong. You can leave out mARCUSTSTAT13, it is not used.
2. No, the user has to provide IDs.
3. N/A
4. Yes, .Read, change fields, .Update
 
Great. Thanks again

I have customer being created and updated.

Now onto AR Invoices. I have my test invoice getting created. My question is, is using the account set the only way to set the AR recievables control?
 
Yes it is.
You do not have to set it, since the customer is assigned to an Account Set, and this will be used by default. The only time you would set the Account Set is if you want to specifically change the Account Set (and AR control account).
From an accounting point of view this does not make sense, but it is there and it can be used.
 
I need to post multiple invoices to a batch. Right now my code is creating a new batch for every invoice. I now in other Accounting packages we connect to we set the batch number on the invoice and they all get grouped together.

Is there way to do that in AccPac or is it create the batch, then get the batch id and use it for the invoices? If so what is the best method to get this accomplished?
 
The steps would be:

Create batch

Do
Create header
Put header fields
Do
Create detail
Put detail fields
Insert detail
Loop
Insert header
Loop

So create one batch, but loop through your headers to add multiple invoices to the same batch.
 
Got it, thanks. I have been dealing with other priorities for awhile.

Now I'm back to the remote connection.

I used the database setup app to add a new SAMSYS and SAMINC connection on another server. When I attempt to login into Accpac to test connection I get the error that
You cannot open this company because another task has locked the database. Wait for the task to be completed, then select the company again.

I other instances has not had anyone in it for a couple days and I know that it was rebooted this morning.

What am I missing?

Thanks again
 
1. Time to start a new thread with a new title
2. Your problem is probably that the Path to Accpac.Exe isn't the same as HKEY_LOCAL_MACHINE\SOFTWARE\ACCPAC International, Inc.\ACCPAC\Configuration\Programs, or some other basic configuration problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top