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
 
You can filter out a lot of the crap recorded in the macro.
I'm not a .Net fan, this is far simpler to do in VB6.

Code:
      Private Sub EnterAPInvoice()
         Try

            mAPINVOICE1batch.RecordCreate(1)
            mAPINVOICE1batchFields.FieldByName("BTCHDESC").SetValue("test description sent", True)   ' Description
            mAPINVOICE1batch.Update()

            mAPINVOICE1header.RecordCreate(2)
            mAPINVOICE1headerFields.FieldByName("IDVEND").SetValue("1400", True)                       ' Vendor Number
            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


            mAPINVOICE1detail1.RecordCreate(2)
	    'You need to set the GL expense account here....
            mAPINVOICE1detail1Fields.FieldByName("AMTDIST").SetValue("50.000", True)                   ' Distributed Amount
	    mAPINVOICE1detail1.Insert()

            mAPINVOICE1detail1.RecordCreate(2)
	    'You need to set the GL expense account here....
            mAPINVOICE1detail1Fields.FieldByName("AMTDIST").SetValue("40.000", True)                   ' Distributed Amount
	    mAPINVOICE1detail1.Insert()

            mAPINVOICE1headerFields.FieldByName("AMTGROSTOT").SetValue("90.000", True)                 ' Document Total Including Tax
            mAPINVOICE1header.Insert()

         Catch ex As Exception
            ErrorHandler(ex)
         End Try
      End Sub
 
Sorry I missed that you use a dist set in the header, in this case you can loop through the details and update the amount field.
Something like
Code:
Do while mAPINVOICE1detail1.GoNext
    'You need to figure out which line you are on and which amount to use mAPINVOICE1detail1Fields.FieldByName("AMTDIST").SetValue("50.000", True)
   mAPINVOICE1detail1.Update
loop
 
I prefer not to use dist sets and I insert the details I require.
 
Thank you for your help and quick response. I should have known better when I was told to just to take the macro.

What is the fieldname for the GLAccount?

Is there a resource that has this information?
 
Recording a macro is the best starting point, so you started out right - I start by recording a macro all the time.
Edit a vendor (AP Vendors, Vendors) and set Invoicing, Distribute By to None. When you create an invoice for this vendor it will not throw in a Dist Set, in which case you need to enter the GL expense account.
Now record a macro while you add an invoice for this vendor and you will get the required fields.
I could have simply given you the field name, but telling you how to get it is better.
Another way is to click Start, Run and type in AccpacViewInfo and press Enter. Expand AP, then open AP0022, GL account is on the list.

 
Thanks again. I definitely want understand this, so thanks for the info.

About the dist set. My question what if my client has a dist set for a vendor, but my code is not using one. Does this cause a problem or does it still add the ap invoice? I don't want to code something expecting my clients to have all their vendors set a particular why, if I can help it.

I took out the invoice1detail2, 3, 4 compose calls and changed my setvalues to use the view's fields collection (instead of assigning it to a variable).

Now when I try and set the vendor id I get the following error

mAPINVOICE1header.Fields.FieldByName("IDVEND").SetValue("1400", True) ' Vendor Number


Error HRESULT E_FAIL has been returned from a call to a COM component.

1400 is a valid vendor id

again thanks for your help
 
1. Dist Set - don't worry about it, if you add detail lines in your code then the dist set will be ignored. The other way round does not work, if you assume there is a dist set and there is none.

2. Do not take out the compositions, this could be why you are getting an error.

3. Do you have an error handling routine, this will give you an informative error.
 
Thanks again for your help. I was able to get an AP invoice inserted.
 
No, that is if you are running Accpac web deployment, and that is a waste of time.
Some other people have, and maybe they will reply.
 
I don't think I am doing their web deployment. My code is a business object that is running on a website, but I am taking data from my UI, populating AccPacc's objects, then submitting to AccPac.

Is that what AccPac considers web deployment?

My issue COULD be that, right now, I am not certain that my dll will be running on the same server that AccPac is installed.

AccPac help stated that I just need to call remoteconnect and all is good.

Thanks
 
If you can launch Accpac from an icon on the computer where your code is running then you are running a desktop deployment, then you do not need remoteconnect. This is the preferred method.
If you launch Accpac from Internet Explorer then you are running web deployment, this is bad news.
 
Ok, No web deployment here then.

So is it possible to do what I am trying. Run MY application on my system, that as at least the accpac desktop installed, and post data to an accpac database on another server?

 
Yes, in the Accpac Database setup you specify the location of the data, this can be any other server on the LAN that is running the database engine (Pervasive/MS SQL/Oracle/DB2).
 
Thanks for the reply. I still don't have the remote connection working, but I have some investigation to do on my side first.

What is the quickest way to get a vendor listing? I tried recording a macro when I selected the AP vendor list but it did not help.
 
Yes AP0015.

Something like in VB6

Code:
mAPVen = mDBLinkCmpRW.OpenView("AP0015")
Do While mAPVen.GoNext
   'This will loop thru all the vendors
loop

If you want one vendor:
Code:
mAPven.Fields("VENDORID").PutWithoutVerification "1200"
If mAPVen.Read then
  'Vendor found
else
  'Vendor not found
end if
 
Again...Thank you for your reply. Your help has been tremendous and it is greatly valued.

Thanks
 
Is there a close connection that I should be calling?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top