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!

Importing Batch to ACCPAC A/P 1

Status
Not open for further replies.

POSOL

Programmer
Jul 2, 2004
16
CA
Hi,

I am writing a program to import invoices into ACCPAC batch. Following is the code fragment that import (should import:) ) data into ACCPAC.

1. I am not sure how all this VIEWs thing works - I've seen in sample macros that view gets declared, initialize and COMPOSED. MY question: I would logically get why declared and initialized, but why do we need composed, what is happening at initialization time?

2. I got error messages (inside of the code in red):

1st - I don't see why there is 1st error message?

2nd - The Amount ACCPAC talks in the second errorMSG is a field that is a part of APINVOICINGdetail1 view, but I can not update two views at the same time. Probably I have to Compose my views differently, but I don't really know what composition do?

I would appreciate any help,

P.S. I saw a post not long ago: some one was talking about 'creating program by the book, Declare views, initialize, COMPOSE' - any Idea where I can look up into that kind of book,.. well any kind will do?!

Thank you for your posts


Dim APINVOICEbatch As AccpacCOMAPI.AccpacView
Dim APINVOICEbatchFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0020", APINVOICEbatch
Set APINVOICEbatchFields = APINVOICEbatch.Fields

Dim APINVOICEheader As AccpacCOMAPI.AccpacView
Dim APINVOICEheaderFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0021", APINVOICEheader
Set APINVOICEheaderFields = APINVOICEheader.Fields

Dim APINVOICEdetail1 As AccpacCOMAPI.AccpacView
Dim APINVOICEdetail1Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0022", APINVOICEdetail1
Set APINVOICEdetail1Fields = APINVOICEdetail1.Fields

Dim APINVOICEdetail2 As AccpacCOMAPI.AccpacView
Dim APINVOICEdetail2Fields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "AP0023", APINVOICEdetail2
Set APINVOICEdetail2Fields = APINVOICEdetail2.Fields

APINVOICEbatch.Compose Array(APINVOICEheader)

APINVOICEheader.Compose Array(APINVOICEbatch, APINVOICEdetail1, APINVOICEdetail2)

APINVOICEdetail1.Compose Array(APINVOICEheader, APINVOICEbatch)

APINVOICEdetail2.Compose Array(APINVOICEheader)

'ADDING DATA TO BATCH**************
' Batch Number
APINVOICEbatchFields("CNTBTCH").PutWithoutVerification ("0")
APINVOICEbatch.Init

'Getting new Batch Number
BatchNo = APINVOICEbatchFields("CNTBTCH").Value

'Adding comment to the new Batch
APINVOICEbatchFields("BTCHDESC").PutWithoutVerification (BatchDescription)
'Setting up the number of records imported
APINVOICEbatchFields("CNTINVCENT").PutWithoutVerification (rstSourceDB.RecordCount)

APINVOICEbatch.Update

'counter for record number
Dim i As Integer
i = 1

'ADDING DATA TO HEADER
rstSourceDB.MoveFirst
Do
APINVOICEheader.Init

APINVOICEheaderFields("CNTBTCH").Value = BatchNo
APINVOICEheaderFields("CNTITEM").Value = i
APINVOICEheaderFields("IDVEND").Value = rstSourceDB!VENDORID
APINVOICEheaderFields("IDINVC").Value = rstSourceDB![Contractor Invoice No]
APINVOICEheaderFields("LASTLINE").Value = 1
APINVOICEheaderFields("ORDRNBR").Value = rstSourceDB![OCHC Workorder No]
'APINVOICEheaderFields("PONBR").Value = rstSourceDB![Contract No]
APINVOICEheaderFields("INVCDESC").Value = rstSourceDB![Invoice Description]
APINVOICEheaderFields("DATEINVC").Value = rstSourceDB![Invoice Date]
APINVOICEheaderFields("DATEDUE").Value = rstSourceDB![Invoice Date]
'APINVOICEheaderFields("AMTDUE").Value = rstSourceDB![Gross Payment]
APINVOICEheaderFields("AMTGROSTOT").Value = rstSourceDB![Gross Payment]

'My program crashes on Update, 2 errors:
1. "Invoice. Record has been modified by another program."
2. "Warning. The distributed amount does not equal the document total."


APINVOICEheader.Update

i = i + 1
rstSourceDB.MoveNext
Loop While rstSourceDB.EOF = False
Convert = True
 
Try it like this:

' Get the next batch number
ApInvoiceBatch.Init
ApInvoiceBatch.Fields("BTCHDESC").Value = "My Batch"
ApInvoiceBatch.Update
sNextAPBatch = ApInvoiceBatch.Fields("CNTBTCH")


' Start the AP invoice
ApInvoiceHeader.Fields("CNTBTCH").PutWithoutVerification (sNextApBatch) ApInvoiceHeader.Fields("CNTITEM").PutWithoutVerification ("0")
ApInvoiceHeader.Browse "CNTBTCH = " + sNextApBatch, 1
ApInvoiceHeader.Fetch
ApInvoiceHeader.Fields("CNTITEM").PutWithoutVerification ("0")
ApInvoiceHeader.Init
ApInvoiceHeader.Fields("IDVEND") = sAPVENDOR
ApInvoiceDetail1.Init

' Loop starts here:
recStuff.Open "(whatever you're pulling from)"
do until recStuff.EOF
ApInvoiceDetail1.Fields("IDGLACCT") = recstuff!GLAccount
ApInvoiceDetail1.Fields("AMTDIST") = recStuff.Amount
ApInvoiceDetail1.Fields("TEXTDESC") = recStuff.Descrip
ApInvoiceDetail1.Insert
nTotalAPAmount = nTotalAPAmount + recStuff.Amount
recStuff.MoveNext
Loop

ApInvoiceHeader.Fields("AMTGROSTOT") = nTotalAPAmount
ApInvoiceHeader.Insert


Jay Converse
IT Director
Systemlink, Inc.
 
Let me try to explain. Composing the views estabilshes working relationships between the related views. The header is related to or belongs to the batch, the details to the header, etc. Composing allows the views to comunicate with each other, to automatically check that the data is correct and not corrupt. It allows the views to place default values where it can so you don't have to. In my opinion, always compose the views properly (for the views that can be composed) it will make your life easier. Even if you are only reading values from a single view, compose it (the search through the view will be much faster).

The reason you get more than one error is that the ACCPAC errors is a collection. The COMAPI has noticed several errors (a single error might cuase many others) and placed them all into the collection. Sometimes you can get 100's of errors, mostly the same error with the last couple in the collection different and only those two are really meaningful. A pain yes, but it is a standard for databases. ADO works the same way.

I think that you may be getting error two because you don't have a detail line in the invoice. I would suggest that you record a macro and enter an invoice through ACCPAC and see what the macro contains. You will then see all the views and fields that you need to populate.

Unfortunatly it is a bit of trial and error because ACCPAC does not have any thourough documentation on the COMAPI.

Hope this helps in some way.



zemp
 
Thank you Jayconverse and Zemp for your postings.

That helped me a lot - now I am at the proces of tuning my App.

I consider myself just a newbie in ACCPAC programming,
and you guys are the only source of info I get.

I would never started working with ACCPAC if not this forum and not you.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top